Database Reference
In-Depth Information
Figure 24.8
The SELECT …
INTO Statement.
cursor declaration section creates a RECORD object called RARTIST and
that no opening and closing cursor operations are required.
In this example, the cursor is declared and has a name of CARTIST.
However, instead of declaring a record variable and using OPEN,
FETCH, and CLOSE to retrieve rows, all that is needed is the FOR
clause. The loop automatically opens the cursor and reads each row and
places it into the RARTIST variable. Inside the loop, the artist's name is
displayed on the screen. When no more rows are found, the loop automat-
ically closes the cursor and ends the loop. The result of the following code
is shown in Figure 24.9.
SET SERVEROUTPUT ON;
DECLARE
CURSOR CARTIST IS SELECT * FROM ARTIST ORDER BY NAME;
BEGIN
FOR RARTIST IN CARTIST LOOP
DBMS_OUTPUT.PUT_LINE(RARTIST.NAME);
END LOOP;
END;
/
SET SERVEROUTPUT OFF;
Search WWH ::




Custom Search