我创建了一个返回 SYS_REFCURSOR 的 oracle 函数。问题是我需要返回的数据可能是由两个不同的查询产生的。基本上,如果第一个查询没有返回数据,那么我需要运行一个不同的查询,然后返回 refcursor。
这是我的大创意
FUNCTION F_RETURN_RECORD(
P_VAL in NUMBER)
RETURN SYS_REFCURSOR AS TYPE R_CURSOR IS REF CURSOR;
my_record_1 R_CURSOR;
processed_record R_CURSOR;
BEGIN
OPEN my_record_1 FOR select e.COL1, e.COL2,a.COL1,e.COL3, e.COL4,
e.COL5, e.COL6, e.COL7, e.COL8, e.COL9,
e.COL10, e.COL11
from table1 e
inner join table2 a on e.COL2=a.COL2
where e.COL1=P_VAL;
if my_record_1%notfound
then
close my_record_1;
OPEN processed_record for select e.COL1, e.COL2,a.COL1,e.COL3, e.COL4,
e.COL5, e.COL6, e.COL7, e.COL8, e.COL9,
e.COL10, e.COL11, e.COL12, e.COL13, e.COL14
from table3 e
inner join table2 a on e.COL2=a.COL2
inner join table 4 b on a.col1=b.col2
where e.COL1=P_VAL;
return processed_record;
end if;
DBMS_OUTPUT.PUT_LINE('Returning data.................');
return my_record_1;
END F_RETURN_RECORD;
无论出于何种原因if my_record_1%notfound
,检查都不起作用。我想我的问题是如何检查my_record_1游标是否不包含任何数据?
谢谢