RSS

9.2 Using Cursor FOR Loops and Nested Cursors

13 May

There is an alternative way to handle cursors. It is called the cursor FOR loop because of the simplified syntax that is used. With a cursor FOR loop, the process of opening, fetching, and closing is handled implicitly. This makes the blocks much easier to code and maintain.

 

The cursor FOR loop specifies a sequence of statements to be repeated once for each row returned by the cursor. Use the cursor FOR loop if you need to FETCH and PROCESS every record from a cursor until you want to stop processing and exit the loop.

 

DECLARE

CURSOR c_student IS

SELECT student_id, last_name, first_name

FROM student

WHERE student_id < 110;

BEGIN

FOR r_student IN c_student LOOP

INSERT INTO table_log

VALUE(r_student.last_name);

END LOOP;

END;

Advertisements
 
Leave a comment

Posted by on 05/13/2010 in ORACLE

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: