oracle 将游标中的数据合并为一个

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4085014/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 21:49:32  来源:igfitidea点击:

Union data from cursors into one

oracleplsqloracle11gcursors

提问by ksogor

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?

我可以以某种方式将多个游标中的数据合并到另一个游标中吗?没有临时表或类似表的数据类型是可能的吗?

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

编辑:联合的光标计数实际上是 n(其中 n 是 1、2、3 等,由另一个程序检测)。

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   

采纳答案by andr

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

不,这不可能。AskTom 上有一个关于这个问题的很好的讨论,看看那里提供的一些解决方法可以帮助你。

回答by vc 74

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

您可以通过创建一个流水线函数来实现这一点,该函数将允许您执行以下操作

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