这是程序:
- 打开游标,然后通过批量收集获取选择查询的输出。
- 问题是所有 ID 都存储在批量收集中,但我无法通过使用批量收集变量作为输入来循环第二个选择查询,它只考虑第一个 ID 而不是全部。
- OUTPUT 应该是 SYS_REFCURSOR,请说明我在这里缺少什么
表1的测试数据:
ID | 货币 | T_ID |
---|---|---|
10 | 英镑 | PB1 |
15 | 英镑 | RB |
20 | 英镑 | 抄送 |
25 | 澳元 | 直流 |
基于 t_id 我正在获取相应的 ID,然后在进一步的 select for 循环语句中使用这些 ID。
PROC 通过 SYS_REFCURSOR 的当前输出:
ID | 国家 | 帐户 |
---|---|---|
10 | 英国 | PB1 |
预期输出:
ID | 国家 | 帐户 |
---|---|---|
10 | 英国 | PB1 |
15 | 威尔士 | RB |
20 | 上海 | 抄送 |
create or replace procedure myproc (i_id in varchar2, rc out sys_refcursor)
as
cursor names_cur is
select id from table1 where currency='GBP' and t_id=i_id;
names_t names_cur%ROWTYPE;
type names_ntt is table of names_t%TYPE;
l_names names_ntt;
begin
open names_cur;
fetch names_cur bulk collect into l_names ; --Inside l_names (10,15 & 20) would be stored
close names_cur;
--iSSUE IS WITH BELOW FOR LOOP
for cur in l_names.first..l_names.last loop
open rc for --For the below select I want to iterate l_names so for the above scenario it should iterate thrice
select s.id,s.country,s.account from table2 s where s.id=l_names(cur).id;
end loop;
end myproc;