我有一个巨大的子查询,它解析为我的主查询的IN子句,如下所示:
DELETE from my_table where one_column IN (my huge complicated sub query);
我的子查询将返回只有一列NUMBER类型的多条记录。并且在一个程序中。
对于EG:我的子查询的结果集将如下所示:
----------
one_column
----------
23
24
27
34
39
43
48
我的主要查询是根据子查询返回的值删除记录。
我的要求是:我需要将子查询的输出作为引用游标返回。 我尝试了什么:按原样执行查询,然后在删除后打开引用游标并再次执行子查询并返回它。这很有效。但我不想要这种冗余。
DELETE from my_table where one_column IN (my huge complicated sub query);
Open my_cursor for
my huge complicated sub query;
(这是my_cursor在包中的变量)
我想做什么:
DECLARE
my_cursor_2 SYS_REFCURSOR;
BEGIN
Open my_cursor_2 for
my huge complicated sub query;
my_cursor := my_cursor_2; // something like this - I know this will obviosuly create one more handle for the same resultset and wont serve my purpose. Basically I want to clone the cursor and use it as a different one
DELETE from my_table where one_column IN (read from my_cursor_2 for input to the delete query);
And return my_cursor as out var of the procedure
有可能吗?或其他任何更好的方法来实现这一目标?