PL/SQL Section 5 Quiz

 1. Which of the following statements about the %ISOPEN cursor attribute is true?


(1) Point

2. Assume that you have declared a cursor called C_EMP. Which of the following statements about C_EMP is correct? (Choose two.)

(1) Point

3. You execute the following code:

DECLARE
  CURSOR emp_curs IS SELECT last_name FROM employees;
  v_last_name employees.last_name%TYPE;
BEGIN
  OPEN emp_curs;
  LOOP -- Point A
   FETCH emp_curs INTO v_last_name;
   EXIT WHEN emp_curs%NOTFOUND;
   DBMS_OUTPUT.PUT_LINE(v_last_name);
  END LOOP;
  CLOSE emp_curs;
END;

At Point A (after you have OPENed the cursor) another user updates an employee's last_name from 'Smith' to 'Jones' and immediately COMMITs.

When your block FETCHes this row, which value will be fetched and displayed?


(1) Point

4. One (and only one) employee has LAST_NAME = 'Grant'. You need to code:
SELECT ... FROM employees WHERE last_name = 'Grant';

Which type of cursor should you use, and why?


(1) Point

5. You cannot OPEN or CLOSE an implicit cursor. Why not?

(1) Point
11. What is wrong with the following code?

DECLARE
    CURSOR dept_curs IS SELECT * FROM departments;
BEGIN
    FOR dept_rec IN dept_curs LOOP
       DBMS_OUTPUT.PUT_LINE(dept_curs%ROWCOUNT || dept_rec.department_name):
    END LOOP;
    DBMS_OUTPUT.PUT_LINE(dept_rec.department_id);
END;


(1) Point

12. A cursor FOR loop using a subquery can shorten code length when compared to an explicit cursor declaration. True or False?

(1) Point

13. What is the difference between the following two blocks of code?

--Block A
DECLARE
    CURSOR emp_cursor IS
    SELECT employee_id, last_name
    FROM employees
    WHERE department_id = 80
    FOR UPDATE OF salary;

--Block B
DECLARE
    CURSOR emp_cursor IS
    SELECT employee_id, last_name
    FROM employees
    WHERE department_id = 80
    FOR UPDATE OF salary
    NOWAIT;


(1) Point

14. You have declared a cursor as SELECT .... FOR UPDATE; You have OPENed the cursor and locked the FETCHed rows. When are these row locks released?

(1) Point

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

(1) Point

1. The employees table contains 11 columns. The following block declares a cursor and a record based on the cursor:

DECLARE
    CURSOR emp_curs IS
       SELECT * FROM employees;
    v_emp_rec emp_curs%ROWTYPE;

A twelfth column is now added to the employees table. Which of the following statements is true?


(1) Point

2. You can reference explicit cursor attributes directly in a SQL statement. True or False?

(1) Point

3. What is missing from the following cursor declaration?

  CURSOR emp_curs
IS
SELECT * FROM departments
  WHERE location_id = p_loc_id;


(1) Point

4. A cursor has been declared as:
CURSOR c_curs (p_param VARCHAR2) IS
   SELECT * FROM mytable
   WHERE mycolumn = p_param;
Which of the following will open the cursor successfully?

(1) Point

5. Which statement correctly places the employee id and last name into the stated variables?

DECLARE
  CURSOR emp_cursor IS
  SELECT employee_id, last_name FROM employees
  WHERE department_id = 30;
  v_empno employees.employee_id%TYPE;
  v_lname employees.last_name%TYPE;
BEGIN
  OPEN emp_cursor;
-- Point A
...


(1) Point

Komentar

Postingan populer dari blog ini

PL/SQL Section 13 Quiz

PL/SQL Section 14 Quiz