将游标中的数据合并为一个 [英] 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?
并集的游标数实际上是n(其中n是1、2、3等,由另一个过程检测).
Cursor count for union actually is n (where n is 1, 2, 3, etc, detecting by another procedure).
例如:
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;
/
预期输出:
---
1
1
推荐答案
否,这是不可能的.有很好的讨论在AskTom关于此问题,请看一下提供的可以帮助您的一些变通方法.
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.
这篇关于将游标中的数据合并为一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!