我有以下PL / SQl过程(下面的代码),此过程从Cursor调用PL / SQL函数。但是,此函数的返回类型是SYS_REFCURSOR
我的目标是循环游标并将记录插入表中。简单。
首先是功能:
FUNCTION DOB_DIFF (JOB1 NUMBER, JOB2 NUMBER, CASE_NUMBER NUMBER DEFAULT 0)
RETURN SYS_REFCURSOR IS
XDO_CURSOR SYS_REFCURSOR;
BEGIN
OPEN XDO_CURSOR FOR
'SELECT A.X,
A.Y,
''BNFCRY'' AS TYPE,
B.Z AS DOB
FROM TABLE1 B, TABLE A
WHERE B.X = A.X
AND B.Y = A.Y';
RETURN XDO_CURSOR;
END DOB_DIFF;
这是程序&到目前为止我所拥有的:
create or replace PROCEDURE CALL_FUNC1 (USER_ID IN VARCHAR2, JOB_NR1 IN NUMBER, JOB_NR2 IN NUMBER, CASE_NUM NUMBER DEFAULT 0) AS
CURSOR DOB_DIFF IS
SELECT PKG_PACKAGE1.DOB_DIFF (JOB_NR1, JOB_NR2, CASE_NUM) FROM DUAL;
BEGIN
FOR I IN DOB_DIFF LOOP
INSERT INTO IPVOWN.PRT_BEN_DOB_DIFF (X, Y, TYPE, DOB)
VALUES (I.X, I.Y, I.TYPE, I.DOB);
END LOOP;
COMMIT;
END CALL_FUNC1;
我收到以下错误,我做错了什么?似乎我无法遍历游标,因为函数的返回值是SYS_REFCURSOR,它是一个列表。如果是这种情况,那我怎样才能遍历游标中的列表?
Error(61,2): PLS-00989: Cursor Variable in record, object, or collection is not supported by this release
提前致谢。
答案 0 :(得分:1)
您的代码需要更像:
create or replace procedure call_func1
( user_id in varchar2
, job_nr1 in number
, job_nr2 in number
, case_num number default 0
)
as
dob_diff sys_refcursor;
dob_diff_rec ipvown.prt_ben_dob_diff%rowtype;
begin
dob_diff := pkg_package1.dob_diff (job_nr1, job_nr2, case_num);
loop
fetch dob_diff
into dob_diff_rec.x
, dob_diff_rec.y
, dob_diff_rec.type
, dob_diff_rec.dob;
exit when dob_diff%notfound;
insert into ipvown.prt_ben_dob_diff (x, y, type, dob)
values ( dob_diff_rec.x
, dob_diff_rec.y
, dob_diff_rec.type
, dob_diff_rec.dob
);
end loop;
close dob_diff;
end call_func1;
如果您真的喜欢,可以用大写字母写出: - )