Intermediate

Q:

12-7.

Here is one possible implementation:

DECLARE
   TYPE emp_cvt IS REF CURSOR RETURN employee%ROWTYPE;
   employees emp_cvt;
   one_employee employees%ROWTYPE;
BEGIN
   OPEN employees FOR SELECT * FROM employee;
   LOOP
      FETCH employees INTO one_employee;
      EXIT WHEN employees%NOTFOUND;
      double_salary (one_employee.employee_id, one_employee.salary);
   END LOOP;
   CLOSE employees;
END;
/

Q:

12-8.

Here are the rules to keep in mind in solving this problem:

  1. The statement must be valid.

  2. The number and datatypes of the record being declared must be compatible with the record structure in the RETURN clause of the REF CURSOR statement.

The declarations are:

  1. Valid. This statement (as well as (e) and (g)) declares records that can be used in FETCH statements against the_finest_cv cursor variable. This one declares a standard table-based record, exactly the same structure used in the REF CURSOR.

  2. Invalid. Doesn’t compile. You can’t use %ROWTYPE against a REF CURSOR, only against a cursor variable.

  3. Invalid. Doesn’t compile. You can’t declare a record of type REF CURSOR; you can only declare cursor variables based on REF CURSOR types.

  4. Invalid. Doesn’t compile. You need to add %ROWTYPE to this statement.

  5. Valid. This statement relies on a programmer-defined record that has the same structure as the table, so that works just fine.

  6. Invalid. Doesn’t compile. You can’t put a %ROWTYPE at the end of a record TYPE; it already is a type.

  7. Valid. This statement demonstrates that you can declare a record from a cursor variable ...

Get Oracle PL/SQL Programming: A Developer's Workbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.