You are on page 1of 4

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_nam e); END LOOP; IF emp_record.last_name = 'Patel' THEN ... Mark for Review (1) Poi nts 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_OUTP UT.PUT_LINE(emp_cursor.last_name); Nothing is wrong, the code will execute corre ctly. Correct 2. You have declared a cursor as follows: CURSOR loc_curs IS SELECT * FR OM 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 ... F OR loc_rec IN loc_curs LOOP ... (*) Correct 3. Look at the following code: DECLARE CURSOR emp_cursor IS SELECT * FRO M employees;

BEGIN FOR emp_record IN emp_cursor LOOP DBMS_OUTPUT.PUT_LINE( --Point A -- ); EN D 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 emp loyees.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) LOO P ... 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 lengt h when compared to an explicit cursor declaration. True or False? Mark for Revie w (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 %NOTFO UND. (*) The execution speed is slower. You cannot declare the cursor in the dec laration section. You cannot use the cursor to join two or more tables. There ar e 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 th e same cursor twice at the same time. Because there is less code, the loop execu tes faster. %ROWCOUNT increments automatically each time a row is FETCHed. Correct

You might also like