Pass cursor as a record type input to another procedure

Hi,

Please let me know the below logic is correct or not
declare
    cursor cur_data
    IS
    select *
    from dba_objects
    where rownum <= 10;

begin
    FOR rec_cur_data IN cur_data
    LOOP
        insert_data (rec_cur_data);  -- Record type is input parameter to this insert_date procedure   
    
    END LOOP;

end;

Open in new window

Suriyaraj_SudalaiappanAsked:
Who is Participating?
 
sdstuberCommented:
alternately, you could use the FOR loop as you had it and copy the implicit record to an explicit record then pass the explicit.


Also note, you might not want to do the inserts row-by-row anyway, if you can do them in bulk it will be more efficient
0
 
enachemcCommented:
use a ref_cursor (reference to a cursor) for this
0
 
sdstuberCommented:
not quite, you can't pass the implicit record from the FOR construct  you'll have to declare it explicitly


DECLARE
    CURSOR cur_data
    IS
        SELECT *
          FROM dba_objects
         WHERE ROWNUM <= 10;

    rec_cur_data cur_data%ROWTYPE;
BEGIN
    OPEN cur_data;

    LOOP
        FETCH cur_data INTO rec_cur_data;

        EXIT WHEN cur_data%NOTFOUND;

        insert_data(rec_cur_data); -- Record type is input parameter to this insert_date procedure
    END LOOP;
END;
0
 
Suriyaraj_SudalaiappanAuthor Commented:
GOOD ONE
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.