The syntax for the OPEN statement is simplicity itself:
OPEN <cursor_name> [ ( argument [, argument ...] ) ];
where <cursor_name> is the name of the cursor you declared and the arguments are the values to be passed if the cursor was declared with a parameter list.
When you open a cursor, PL/SQL executes the query for that cursor. It also identifies the active set of data -- that is, the rows from all involved tables that meet the criteria in the WHERE clause and join conditions. The OPEN does not itself actually retrieve any of these rows -- that action is performed by the FETCH statement.
Regardless of when you perform the first fetch, however, the read consistency model in the Oracle RDBMS guarantees that all fetches will reflect the data as it existed when the cursor was opened. In other words, from the moment you open your cursor until the moment that cursor is closed, all data fetched through the cursor will ignore any inserts, updates, and deletes performed after the cursor was opened.
Furthermore, if the SELECT statement in your cursor uses a FOR UPDATE clause, then, when the cursor is opened, all the rows identified by the query are locked. (This topic is covered in Section 6.11, "SELECT FOR UPDATE in Cursors" later in this chapter.)
ORA-06511: PL/SQL: cursor already open
IF NOT company_cur%ISOPEN THEN OPEN company_cur; END IF;
Section 6.9, "Cursor Attributes" later in the chapter, explains the different cursor attributes and how to make best use of them in your programs.
Copyright (c) 2000 O'Reilly & Associates. All rights reserved.