开发者

Union data from cursors into one

I have stored procedure which executes another stored procedure several times. I need union and return data, which I have after executing second procedure.

Can I in some way union data from several cursors into one another cursor? It is possible without temporary tables or table-like datatype开发者_如何学JAVA?

EDIT: Cursor count for union actually is n (where n is 1, 2, 3, etc, detecting by another procedure).

For example:

CREATE OR REPLACE PROCEDURE proc_data
( data_out OUT SYS_REFCURSOR
) IS
BEGIN
 OPEN data_out FOR SELECT '1' NUM FROM dual;
END;
/

CREATE OR REPLACE PROCEDURE proc_result
( data_out OUT SYS_REFCURSOR
) IS
 data1 SYS_REFCURSOR;
 data2 SYS_REFCURSOR;
BEGIN
 PROC_DATA(data1);
 PROC_DATA(data2);
 -- select data1 and data2 into data_out - how?
END;
/

SET SERVEROUTPUT ON

DECLARE 
 data_out SYS_REFCURSOR;
 temp_row VARCHAR2(10);
BEGIN
 PROC_RESULT(data_out);
  LOOP
    FETCH data_out INTO temp_row;
    EXIT WHEN data_out%NOTFOUND;
    DBMS_OUTPUT.PUT_LINE(temp_row);
  END LOOP;
  CLOSE data_out;
END;
/

expected output:

---
1   
1   


No, it's not possible. There's a nice discussion at AskTom regarding this question, take a look maybe some workarounds provided there can help you.


You can achieve this by creating a pipelined function which will allow you to do

select table(PROC_DATA(data1)) union table(PROC_DATA(data2))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜