Chapter 12. Cursor Variables

Beginner

Q:

12-1.

Statement (b) describes a cursor variable. Rather than pointing directly or in a hardcoded way to a result set, a cursor variable is a pointer to a work area in the System Global Area (SGA).

Q:

12-2.

First, you must declare a cursor variable type, also known as a REF CURSOR. Then you declare a variable based on that cursor. The following is an example:

DECLARE
   TYPE emp_t IS REF CURSOR RETURN emp%ROWTYPE;
   emp_cv emp_t;

Q:

12-3.

The declarations are:

  1. Valid. This format declares a type of REF CURSOR that is not tied to any specific format or result set; this is called a weak or nonrestrictive REF CURSOR.

  2. Invalid.

  3. Invalid.

  4. Valid. This format allows you to declare cursor variables that can fetch rows having the same format as the orders table; this is called a strong or restrictive REF CURSOR.

Statements (b) and (c) are invalid. After the REF CURSOR keywords, you either have simply a semicolon or a RETURN rowtype clause, where rowtype is either a %ROWTYPE definition or the name of a previously defined record type.

Q:

12-4.

The declarations are:

  1. Valid. Only (a) is a valid cursor variable declaration based on the disasters_cvt REF CURSOR.

  2. Invalid. This declaration will fail to compile because of the %ROWTYPE attribute. A REF CURSOR type is already a type; you don’t need to %ROWTYPE it.

  3. Invalid. This declaration will compile, but it simply creates a record with the same structure as a row in the environmental_disaster table, not a cursor variable.

Q:

12-5.

Here is ...

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.