Sei sulla pagina 1di 11

1.

Examine the following code:


DECLARE
CURSOR region_cur IS
SELECT * FROM wf_world_regions;
v_region_rec region_cur%ROWTYPE;
CURSOR country_cur (p_region_id NUMBER) IS
SELECT * FROM wf_countries
WHERE region_id = p_region_id;
v_country_rec country_cur%ROWTYPE;
BEGIN
OPEN region_cur;
LOOP
FETCH region_cur INTO v_region_rec;
EXIT WHEN region_cur%NOTFOUND;
DBMS_OUTPUT.PUT_LINE
(v_region_rec.region_name);
-- Line A --
LOOP
FETCH country_cur INTO v_country_rec;
EXIT WHEN country_cur%NOTFOUND;
......
What would you code at Line A?
 OPEN country_cur (v_region_rec.region_id); (*)
 OPEN country_cur;
 OPEN country_cur (region_cur.region_id);
 OPEN country_cur (p_region_id);
 OPEN country_cur (wf_world_regions.region_id);

2. Which of the following is a good reason to use two cursors in a single PL/SQL block?
 It is the only way to declare a cursor with a parameter.
 When two tables are related to each other (often by a foreign key) and we want to produce a multilevel
report using data from both tables. (*)
 To speed up the execution of the PL/SQL block.
 To allow one cursor to be opened twice at the same time.
 To allow rows to be locked as they are FETCHed.

3. What is one of the advantages of using parameters with a cursor?


 You can use a single cursor to fetch a different set of rows each time the cursor is opened. (*)
 It will execute much faster than a cursor without parameters.
 You can declare the cursor FOR UPDATE.
 You can use a cursor FOR loop.
 You do not need to DECLARE the cursor at all.

4. What is missing from the following cursor declaration?


CURSOR emp_curs IS SELECT * FROM departments
WHERE location_id = p_loc_id;
 Nothing is wrong; the cursor declaration is correct.
 The declaration is invalid. You cannot reference a cursor parameter in a WHERE clause.
 A parameter is missing. The parameter should be coded as: (p_loc_id IN NUMBER)
 A parameter is missing. The parameter should be coded as: (p_loc_id NUMBER) (*)

5. What is wrong with the following piece of code?


BEGIN
FOR emp_record IN emp_cursor LOOP
DBMS_OUTPUT.PUT_LINE(emp_record.last_name);
END LOOP;
IF emp_record.last_name = 'Patel' THEN ...
 It should read: DBMS_OUTPUT.PUT_LINE(emp_cursor.last_name);
 Nothing is wrong; the code will execute correctly.
 The cursor has not been OPENed.
 You cannot reference EMP_RECORD outside the loop. (*)
 EMP_RECORD has not been explicitly declared.

6. What is the DISadvantage of using a cursor FOR loop with a subquery?


 You cannot declare the cursor in the declaration section.
 You cannot reference cursor attributes such as %NOTFOUND. (*)
 You cannot use the cursor to join two or more tables.
 The execution speed is slower.
 There are no disadvantages.

7. You have declared a cursor as follows:


CURSOR loc_curs IS SELECT * FROM locations;
How should you code a FOR loop to use this cursor?
 FOR loc_curs IN loc_rec LOOP ...
 WHILE loc_rec IN loc_curs LOOP ...
 FOR loc_rec IN loc_curs LOOP ... (*)
 IF loc_rec IN loc_curs LOOP ...
 FOR loc_rec IN 1 .. loc_curs%ROWCOUNT LOOP ...

8. Examine the following code:


DECLARE
CURSOR dept_curs IS SELECT department_name FROM departments;
v_dept_name departments.department_name%TYPE;
BEGIN
OPEN dept_curs;
LOOP
FETCH dept_curs INTO v_dept_name;
DBMS_OUTPUT.PUT_LINE(v_dept_name);
EXIT WHEN dept_curs%NOTFOUND;
END LOOP;
CLOSE dept_curs;
END;
There are 10 rows in the DEPARTMENTS table. What will happen when this code is executed?
 A NO_DATA_FOUND exception will be raised.
 10 rows will be displayed.
 The last row will be displayed twice. (*)
 The loop will execute forever; the same 10 rows will be displayed over and over again.
 10 rows will be displayed, followed by a row of NULL values.

9. What will happen when the following code is executed?


DECLARE CURSOR emp_curs IS
SELECT salary FROM employees;
v_salary employees.salary%TYPE;
BEGIN
OPEN emp_curs;
FETCH emp_curs INTO v_salary;
CLOSE emp_curs;
FETCH emp_curs INTO v_salary;
END;
 The block will fail and a TOO_MANY_ROWS exception will be raised.
 The first employee row will be fetched twice.
 The block will fail and an INVALID_CURSOR exception will be raised. (*)
 The first two employee rows will be fetched.

10. What is wrong with the following code?


DECLARE
CURSOR emp_curs IS SELECT last_name, salary FROM employees;
v_last_name employees.last_name%TYPE;
v_salary employees.salary%TYPE;
BEGIN
FETCH emp_curs INTO v_last_name, v_salary;
OPEN emp_curs;
FETCH emp_curs INTO v_last_name, v_salary;
CLOSE emp_curs;
END;
 The first row is FETCHed before the cursor is OPENed. (*)
 When FETCHing more than one row, you MUST use a loop.
 The cursor declaration does not include a WHERE condition.
 The cursor declaration does not include an INTO clause.

11. When must you declare and use an explicit cursor?


 You want to be able to ROLLBACK a transaction if needed.
 You need to SELECT more than one row from a table. (*)
 You want to use a MERGE statement.
 You need to UPDATE more than one row in a table.

12. When can we use the WHERE CURRENT OF clause?


 Only with a DELETE, but not with an UPDATE
 When the cursor has not been OPENed
 When the cursor is based on a single table (not on a join)
 When the cursor is declared as SELECT ... FOR UPDATE ...; (*)
 Only with an UPDATE, but not with a DELETE

13. Examine the following code:


DECLARE
CURSOR c IS SELECT * FROM employees FOR UPDATE;
c_rec c%ROWTYPE;
BEGIN
OPEN c;
FOR i IN 1..20 LOOP
FETCH c INTO c_rec;
IF i = 6 THEN
UPDATE employees SET first_name = 'Joe'
WHERE CURRENT OF c;
END IF;
END LOOP;
CLOSE c;
END;
Which employee row or rows will be updated when this block is executed?
 The 6th fetched row will be updated. (*)
 The block will not compile because the cursor should have been declared .... FOR UPDATE WAIT 5;

 None of these.
 The first 6 fetched rows will be updated.
 No rows will be updated because you locked the rows when the cursor was opened.

14. You have declared the following cursor:


CURSOR country_curs IS
SELECT * FROM wf_countries
ORDER BY country_name;
There are over 200 rows in the WF_COUNTRIES table, but you want to fetch and display only the first 25 rows.
How would you exit from the FETCH loop?
 EXIT WHEN country_curs%FOUND(25);
 EXIT WHEN ROWCOUNT > 25;
 WHEN country_curs > 25 THEN EXIT; END IF;
 EXIT WHEN country_curs%ROWCOUNT > 25; (*)

15. Assume that you have declared a cursor called C_EMP. Which of the following statements about C_EMP is correct?
(Choose two.)
 You can use c_emp%NOTFOUND to exit a loop. (*)
 You can fetch rows when c_emp%ISOPEN evaluates to FALSE.
 You can use c_emp%FOUND after the cursor is closed.
 You can use c_emp%ROWCOUNT to return the number of rows returned by the cursor so far. (*)

16. You can reference explicit cursor attributes directly in a SQL statement. True or False?
 True
 False (*)

17. Which of the following statements about user-defined PL/SQL records is NOT true?
 It can be used as an OUT parameter in a package procedure.
 It can be a component of another PL/SQL record.
 It can be defined as NOT NULL.
 It must contain one or more components, but all the components must have scalar datatypes. (*)
 It is not the same as a row in a database table.

18. In an INDEX BY table of records the record can be _______________________.


 %ROWTYPE (*)
 Either one.
 a user-defined record

19. What will be displayed when the following code is executed?


<<outer>>
DECLARE
v_myvar NUMBER;
BEGIN
v_myvar := 10;
DECLARE
v_myvar NUMBER := 200;
BEGIN
outer.v_myvar := 20;
v_myvar := v_myvar / 0; -- this raises a ZERO_DIVIDE error
outer.v_myvar := 30;
END;
v_myvar := 40;
EXCEPTION
WHEN ZERO_DIVIDE THEN DBMS_OUTPUT.PUT_LINE(v_myvar);
END;
 20 (*)
 40
 200
 10
 30

20. The following code does not violate any constraints and will not raise an ORA-02292 error. What will happen when
the code is executed?
BEGIN
DECLARE
e_constraint_violation EXCEPTION;
PRAGMA EXCEPTION_INIT(e_constraint_violation, -2292);
BEGIN
DBMS_OUTPUT.PUT_LINE('Inner block message');
END;
EXCEPTION
WHEN e_constraint_violation THEN DBMS_OUTPUT.PUT_LINE('Outer block message');
END;
 'Inner block message' will be displayed.
 The code will fail because line 4 should read: PRAGMA EXCEPTION_INIT(-2292, e_constraint_violation);

 The code will fail because the exception is declared in the inner block but is referenced in the outer
block. (*)
 'Outer block message' will be displayed.

21. Which of these exceptions can be handled by an EXCEPTION section in a PL/SQL block?
 An attempt is made to divide by zero
 Any other kind of exception that can occur within the block
 A SELECT statement returns no rows
 None of these.
 All of these. (*)

22. While a PL/SQL block is executing, more than one exception can occur at the same time. True or False?
 TRUE
 FALSE (*)

23. Which of the following are good practice guidelines for exception handling? (Choose three.)
 Test your code with different combinations of data to see what potential errors can happen. (*)
 Handle specific named exceptions where possible, instead of relying on WHEN OTHERS. (*)
 Allow exceptions to propagate back to the calling environment.
 Use an exception handler whenever there is any possibility of an error occurring. (*)
 Include a WHEN OTHERS handler as the first handler in the exception section.

24. The following line of code is correct. True or False?


RAISE_APPLICATION_ERROR(-21001,'My error message');
 True
 False (*)

25. What is wrong with the following code?


BEGIN
UPDATE employees SET salary = 20000
WHERE job_id = 'CLERK';
IF SQL%ROWCOUNT = 0 THEN
RAISE NO_DATA_FOUND; -- Line A
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No employee was updated');
END;
 You cannot use SQL%ROWCOUNT in conditional control statements such as IF or CASE.
 You cannot explicitly raise predefined Oracle Server errors such as NO_DATA_FOUND.
 NO_DATA_FOUND has not been DECLAREd.
 Nothing is wrong; the code will execute correctly. (*)
 Line A should be: HANDLE NO_DATA_FOUND

26. What is a user-defined exception?


 An exception which is not raised automatically by the Oracle server, but must be declared and raised
explicitly by the PL/SQL programmer. (*)
 An exception handler which the user (the programmer) includes in the EXCEPTION section.
 An exception which has a predefined Oracle error number but no predefined name.
 A predefined Oracle server exception such as NO_DATA_FOUND.

27. An attempt to insert a null value into a NOT NULL table column raises an ORA-01400 exception. How can you code an
exception handler to trap this exception?
 Declare a variable e_null_excep of type EXCEPTION, associate it with ORA-01400 using a PRAGMA
directive, and test for WHEN e_null_excep in the exception section. (*)
 Declare a variable e_null_excep of type VARCHAR2, associate it with ORA-01400 using a PRAGMA
directive, and test for WHEN e_null_excep in the exception section.
 Declare a variable as follows: e_null_excep EXCEPTION := -01400; Then test for WHEN e_null_excep in
the exception section.
 Test for WHEN ORA-1400 in the exception section.

28. A PL/SQL block executes and an Oracle Server exception is raised. Which of the following contains the text message
associated with the exception?
 SQL_MESSAGE_TEXT
 SQL%MESSAGE
 SQLERRM (*)
 SQLCODE

29. Which of the following is NOT a predefined Oracle Server error?


 e_sal_too_high EXCEPTION; (*)
 NO_DATA_FOUND
 DUP_VAL_ON_INDEX
 ZERO_DIVIDE
 TOO_MANY_ROWS

30. Which of the following can NOT be used as the datatype of a procedure parameter?
 A PLSQL record defined using %ROWTYPE
 A non-SQL datatype such as BOOLEAN
 A large object datatype such as CLOB
 The name of another procedure (*)

31. Parameters are a special form of a variable, whose input values are initialized by the calling environment when the
subprogram is called, and whose output values are returned to the calling environment when the subprogram returns
control to the caller.
 True (*)
 False

32. What will happen when the following procedure is called as format_phone (8005551234)?
CREATE OR REPLACE PROCEDURE format_phone
(p_phone_no IN OUT VARCHAR2) IS
BEGIN
p_phone_no := SUBSTR(p_phone_no,1,3) ||
'.' || SUBSTR(p_phone_no,4,3) ||
'.' || SUBSTR(p_phone_no,7);
END format_phone;
 The procedure does not execute because the input variable is not properly declared.
 The phone number 800.555.1234 is placed into the p_phone_no variable. (*)
 The phone number (800) 555-1234 is printed to the screen.
 The phone number 800.555.1234 is printed to the screen.

33. Procedure NUMPROC has been created as:


CREATE PROCEDURE numproc
(x NUMBER, y NUMBER := 100, z NUMBER) IS BEGIN ....
You want to call the procedure, passing arguments of 10 for X and 20 for Z. Which one of the following calls is correct?
 numproc(x=10,z=20);
 numproc(10,z=>20); (*)
 numproc(x=>10,20);
 numproc(10,,20);

34. What is another name for a nested subprogram?


 Local subprogram (*)
 Limited subprogram
 Hosted subprogram

35. Why will the following procedure fail?


CREATE OR REPLACE PROCEDURE mainproc
...
IS
PROCEDURE subproc (...) IS BEGIN
...
BEGIN
...
subproc (...);
...
END;
 Procedure main proc must use the keyword AS not IS
 Procedure subproc does not need the keyword BEGIN
 Procedure subproc does not have an END; statement (*)
 Procedure mainproc does not need the keyword BEGIN

36. Which of the following are benefits of using PL/SQL subprograms rather than anonymous blocks? (Choose three.)

 Do not need to declare variables


 Easier to write
 Better data security (*)
 Faster performance (*)
 Easier code maintenance (*)

37. Examine the following code:


CREATE OR REPLACE FUNCTION add_func
(p_param1 NUMBER, p_param2 NUMBER)
RETURN NUMBER
IS
BEGIN
RETURN (p_param1 + p_param2);
END;
What will be displayed when the following SQL statement is executed?
SELECT add_func(6, add_func(3,8)) FROM dual;
 An error message will be displayed because you cannot nest user-defined functions.
 66
 23
 11
 17 (*)

38. A function must have at least one IN parameter, and must return exactly one value.
 True
 False (*)

39. CREATE FUNCTION get_sal (p_id employees.employee_id%TYPE) RETURN number IS


v_sal employees.salary%TYPE := 0;
BEGIN
SELECT salary INTO v_sal
FROM employees
WHERE employee_id = p_id;
RETURN v_sal;
END get_sal;
Which variable is passed to the function and which variable is returned from the function?
 P_ID is passed and V_SAL is returned. (*)
 SALARY is passed and P_ID is returned.
 GET_SAL is passed and V_SAL is returned.
 EMPLOYEE_ID is passed and SALARY is returned.

40. You need to remove procedure BADPROC from your schema. What is the correct syntax to do this?
 DELETE PROCEDURE badproc;
 DROP PROCEDURE badproc; (*)
 ALTER PROCEDURE badproc DISABLE;
 DROP PROGRAM badproc;

41. The database administrator has granted the DROP ANY PROCEDURE privilege to user KIM. This allows Kim to remove
other users' procedures and functions from the database. How would Kim now drop function GET_EMP, which is owned
by user MEHMET?
 DROP PROGRAM mehmet.get_emp
 DROP FUNCTION mehmet.get_emp (*)
 DROP FUNCTION get_emp FROM mehmet
 DROP PROCEDURE mehmet.get_emp
 None of these

42. Which object privilege can be granted on a single column of a table?


 UPDATE (*)
 DROP
 SELECT
 CREATE
 DELETE

43. Your schema contains two procedures named CHILD1 and CHILD2. You now create a third procedure by executing:
CREATE OR REPLACE PROCEDURE parent IS
BEGIN
child1;
child2;
END;
You now want user JOE to be able to invoke PARENT. Which of the following gives JOE the privileges he needs, but no
unnecessary privileges?
 GRANT EXECUTE ON parent TO joe WITH ADMIN OPTION;
 GRANT EXECUTE ON parent TO joe; (*)
 GRANT EXECUTE ON * TO joe;
 GRANT EXECUTE ON parent TO joe; GRANT EXECUTE ON child1 TO joe; GRANT EXECUTE ON child2 TO
joe;
 GRANT EXECUTE ON parent, child1, child2 TO joe;

44. Which of the following is a benefit of user-defined functions? (Choose 3)


 They can add business rules to the database and can be reused many times. (*)
 They can be used in a WHERE clause to filter data and thereby increase efficiency. (*)
 They can often be used inside SQL statements. (*)
 They can do the same job as built-in system functions such as UPPER and ROUND.

45. Which of the following is a legal location for a function call in a SQL statement? (Choose 3)
 The ORDER BY and GROUP BY clauses of a query (*)
 VALUES clause of an INSERT statement (*)
 WHERE clause in a DELETE statement (*)
 CREATE TABLE statement

46. Which of the following is NOT a benefit of user-defined functions?


 They can add business rules to the database and can be reused many times.
 They can be used in a WHERE clause to filter data.
 They can do the same job as built-in system functions such as UPPER and ROUND. (*)
 They can often be used inside SQL statements.

47. A user executes the following statement:


CREATE INDEX fn_index ON employees(first_name);
What output will the following statement now display:
SELECT index_name
FROM user_indexes
WHERE index_name LIKE 'fn%';
 No output will be displayed (*)
 FN_INDEX
 fn_index FN_INDEX
 fn_index

48. You want to display the names of all tables in your schema, but you have forgotten which Dictionary view to query.
Which of the following will remind you of the name of the correct Dictionary view?

SELECT *
FROM DICTIONARY
WHERE table_name LIKE 'user%table%';

HELP DICTIONARY

SELECT *
FROM DICTIONARY
WHERE table_name LIKE 'USER%TAB%'; (*)

SELECT *
FROM DICTIONARY
WHERE table_name LIKE 'DBA%TABLE%';

SELECT *
FROM USER_OBJECTS
WHERE table_name LIKE '%TABLE%';

49. Procedure GET_EMPS includes a SELECT…FROM EMPLOYEES. The procedure was created using Invoker's Rights.
Which of the following statements are true? (Choose three.)
 The user who executes the procedure does not need any privileges.
 The user who executes the procedure needs EXECUTE privilege on the procedure. (*)
 The user who executes the procedure needs SELECT privilege on EMPLOYEES. (*)
 The creator of the procedure needs SELECT privilege on EMPLOYEES. (*)

50. How do you specify that you want a procedure MYPROCA to use "Definer's Rights"?
 CREATE OR REPLACE PROCEDURE myproca AUTHID CURRENT_USER IS...
 Definer's Rights are the default, therefore no extra code or commands are needed. (*)
 ALTER PROCEDURE myproca TO DEFINER;
 CREATE OR REPLACE PROCEDURE myproca AUTHID OWNER IS...
 GRANT DEFINER TO myprocA;

Potrebbero piacerti anche