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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Suriyaraj_SudalaiappanAuthor Commented:
GOOD ONE
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.