예, 커서 값을 변수에 전달할 수 있습니다. fetch <cursor_name> into <variable_list>
을 사용하면 커서에서 하나 이상의 행을 가져올 수 있습니다. 그런 다음 where
절의 변수를 select into
문으로 사용할 수 있습니다. 당신이 암시 적 커서를 사용하는 경우 예,
declare
cursor c1 is select col1, col2 from table1;
l_col1 table1.col1%type;
l_col2 table1.col2%type;
l_col3 table2.col3%type;
begin
open c1;
loop
fetch c1 into l_col1, l_col2;
exit when c1%notfound;
select col3
into l_col3
from table2 t
where t.col1 = l_col1 --Assuming there is exactly one row in table2
and t.col2 = l_col2; --satisfying these conditions
end loop;
close c1;
end;
, 그럼 그것도 간단 :이 예에서
declare
l_col3 table2.col3%type;
begin
for i in (select col1, col2 from table1)
loop
select col3
into l_col3
from table2 t
where t.col1 = i.col1 --Assuming there is exactly one row in table2
and t.col2 = i.col2; --satisfying these conditions
end loop;
end;
, 그것은
begin
for i in (select t1.col1
, t1.col2
, (select t2.col3
from table2 t2
where t2.col1 = t1.col1 --Assuming there is atmost one such
and t2.col2 = t1.col2 --row in table2
) col3
from table1 t1)
loop
...
end loop;
end;
refcursors이위한 하위 쿼리를 사용하는 것이 더 효율적이다, 하지만 난 항상, 같은 하위 쿼리를 수행 할 수 있습니다 .. 또한 당신은 중첩 테이블을 사용하여 고려해 볼 수 있습니다. (PL SQL 테이블). 중첩 테이블을 실제 테이블로 캐스팅하고 쿼리에 사용할 수 있습니다. –