create or replace PROCEDURE "RESULT" (res1 OUT SYS_REFCURSOR )
IS
Cursor c is Select distinct id,fname,lname,dob,gender,address1 from emp where name like '%B%'
d c%rowtype;
BEGIN
OPEN c;
LOOP
fetch c into d;
exit when c%notfound;
OPEN res1 FOR select e.id from emp e where e.poi_user_id IN (d.id);
End Loop;
END;
程序 RESULT 已编译。
如果我在没有过程的情况下运行查询,我会得到 5 个结果,但是当我使用上面的代码时,它只返回最后一个结果。
SET SERVEROUTPUT ON;
Declare
c SYS_REFCURSOR;
id number;
begin
RESULT(c);
loop
fetch c into id; -- and other columns if needed
exit when c%notfound;
dbms_output.put_line(id);
end loop;
END;
结果 5