Can I pass an explicit cursor to a function/procedure for use in FOR loop?

后端 未结 4 1138
时光说笑
时光说笑 2021-01-12 02:59

I have a procedure that performs some calculations on all records returned by a cursor. It looks a bit like this:

PROCEDURE do_calc(id table.id_column%TYPE)
         


        
4条回答
  •  没有蜡笔的小新
    2021-01-12 04:03

    Try this one, Usong ref cursor.

        declare
        type c is ref cursor;
        c2 c;
        type rec is record(
        id number,
        name varchar(20)
        );
        r rec;
        procedure p1(c1 in out c,r1 in out rec)is begin
    
        loop
        fetch c1 into r1;
        exit when c1%notfound;
        dbms_output.put_line(r1.id || ' ' ||r1.name);
        end loop;
        end;
        begin
        open c2 for select id, name from student;
        p1(c2,r);
        end;
    

提交回复
热议问题