You are on page 1of 3

Test: Quiz: Cursor FOR Loops 1. 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 ... Mark for Review (1) Points EMP_RECORD has not been explicitly declared. The cursor has not been OPENed. You cannot reference EMP_RECORD outside the loop. (*) It should read: DBMS_OUTPUT.PUT_LINE(emp_cursor.last_name); Nothing is wrong, the code will execute correctly.

Correct 2. 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? Mark for Review (1) Points FOR loc_rec IN 1 .. loc_curs%ROWCOUNT LOOP ... WHILE loc_rec IN loc_curs LOOP ... FOR loc_curs IN loc_rec LOOP ... IF loc_rec IN loc_curs LOOP ... FOR loc_rec IN loc_curs LOOP ... (*)

Correct 3. Look at the following code: DECLARE CURSOR emp_cursor IS SELECT * FROM employees;

BEGIN FOR emp_record IN emp_cursor LOOP DBMS_OUTPUT.PUT_LINE( --Point A -- ); END LOOP; END; To display the salary of an employee, what code should you write at Point A? Mark for Review (1) Points emp_record.salary (*) emp_cursor.salary employees.salary emp_record.employees.salary TO_CHAR(salary)

Correct 4. Which one of the following is a valid cursor FOR loop with a subquery? Mark for Review (1) Points FOR emp_rec IN (SELECT last_name || first_name FROM employees) LOOP ... FOR emp_rec IN (SELECT UPPER(last_name) FROM employees) LOOP ... FOR emp_rec IN SELECT last_name, salary*12 "ANNSAL" FROM employees LOOP ... FOR emp_rec IN (SELECT last_name, salary*12 "ANNSAL" FROM employees) LOO P ... (*) None of the above.

Correct 5. A cursor FOR loop using a subquery can extensively shorten code length when compared to an explicit cursor declaration. True or False? Mark for Review (1) Points

True (*) False

Correct 6. What is the DISadvantage of using a cursor FOR loop with a subquery? Mark for Review (1) Points You cannot reference cursor attributes such as %NOTFOUND. (*) The execution speed is slower. You cannot declare the cursor in the declaration section. You cannot use the cursor to join two or more tables. There are no disadvantages.

Correct 7. Which of the following is a benefit of using a cursor FOR loop? Mark for Review (1) Points The exception handling is done automatically. . The OPEN, CLOSE, FETCH and EXIT from the loop are done automatically. (* ) You can OPEN the same cursor twice at the same time. Because there is less code, the loop executes faster. %ROWCOUNT increments automatically each time a row is FETCHed.

Correct

You might also like