How to return multiple rows from the stored procedure? (Oracle PL/SQL)

前端 未结 5 1993
野的像风
野的像风 2020-11-27 11:19

I want to create a stored procedure with one argument which will return different sets of records depending on the argument. What is the way to do this? Can I call it from p

5条回答
  •  鱼传尺愫
    2020-11-27 11:53

    If you want to use it in plain SQL, I would let the store procedure fill a table or temp table with the resulting rows (or go for @Tony Andrews approach).
    If you want to use @Thilo's solution, you have to loop the cursor using PL/SQL. Here an example: (I used a procedure instead of a function, like @Thilo did)

    create or replace procedure myprocedure(retval in out sys_refcursor) is
    begin
      open retval for
        select TABLE_NAME from user_tables;
    end myprocedure;
    
     declare 
       myrefcur sys_refcursor;
       tablename user_tables.TABLE_NAME%type;
     begin
       myprocedure(myrefcur);
       loop
         fetch myrefcur into tablename;
         exit when myrefcur%notfound;
         dbms_output.put_line(tablename);
       end loop;
       close myrefcur;
     end;
    

提交回复
热议问题