我正在尝试使用程序包中的过程,以便我可以在外部程序中调用。我不断遇到符号“CREATE”错误。我已经尝试了很多不同的方法,所以我很抱歉,如果我的代码很乱,我真的迷失了这个
create or replace package GetAllCust as
function GeTAllCust return sys_refcursor;
procedure GET_ALLCUST_FROM_DB(pSysRefCur OUT sys_refcursor);
end GetAllCust;
create or replace package body GetAllCust as
procedure GET_ALLCUST_FROM_DB (pSysRefCur OUT sys_refcursor) as
begin
open pSysRefCur for select * from customer;
return pSysRefCur;
exception
when others then
raise_application_error(-20000, SQLERRM);
end GET_ALLCUST_FROM_DB;
end GetAllCust;
答案 0 :(得分:2)
您已在包规范中定义了函数GeTAllCust
,但在正文中未指定。
另一个错误是程序体中的return语句,这是不需要的。
尝试创建您的包和包体
CREATE OR REPLACE PACKAGE GetAllCust
AS
FUNCTION GeTAllCust
RETURN SYS_REFCURSOR;
PROCEDURE GET_ALLCUST_FROM_DB (pSysRefCur OUT SYS_REFCURSOR);
END GetAllCust;
/
CREATE OR REPLACE PACKAGE BODY GetAllCust
AS
FUNCTION GeTAllCust
RETURN SYS_REFCURSOR
AS
p_cursor SYS_REFCURSOR;
BEGIN
OPEN p_cursor FOR SELECT * FROM customer;
RETURN p_cursor;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
raise_application_error (-20001, SQLERRM);
END GeTAllCust;
PROCEDURE GET_ALLCUST_FROM_DB (pSysRefCur OUT SYS_REFCURSOR)
AS
BEGIN
OPEN pSysRefCur FOR SELECT * FROM customer;
EXCEPTION
WHEN OTHERS
THEN
raise_application_error (-20000, SQLERRM);
END GET_ALLCUST_FROM_DB;
END GetAllCust;
/
答案 1 :(得分:0)
要分析这些问题,请在编译软件包后执行SHOW ERROR
,这将显示问题:
Warning: compiled but with compilation errors
Errors for PACKAGE BODY GETALLCUST
LINE/COL ERROR
-------- -----------------------------------------------------------------
5/5 PLS-00372: In a procedure, RETURN statement cannot contain an exp
5/5 PL/SQL: Statement ignored
2/10 PLS-00323: subprogram or cursor 'GETALLCUST' is declared in a pac
kage specification and must be defined in the package body
所以有两个问题:
GeTAllCust
,但未在正文中实现