我想创建一个在oracle包中执行特定任务的函数,我尝试使用下面的代码,但是它给出了一个我不理解的错误。
CREATE OR REPLACE
PACKAGE DINIDU_EXE_PACKAGE AS
FUNCTION EXE14
(SUP_ID_ SUPPLIER_PART_PROJECT_TAB.SUPPLIER_ID%TYPE,PAR_ID_ SUPPLIER_PART_PROJECT_TAB.PART_ID%TYPE,PRO_ID_ SUPPLIER_PART_PROJECT_TAB.PROJECT_ID%TYPE) RETURN NUMBER IS
QUNTITY_FOR_A_PROJECT_ NUMBER;
BEGIN
SELECT QUENTITY AS QUNTITY_FOR_A_PROJECT_ FROM SUPPLIER_PART_PROJECT_TAB WHERE SUPPLIER_ID=SUP_ID AND PART_ID=PAR_ID AND PRO_ID=PROJECT_ID;
IF QUNTITY_FOR_A_PROJECT_ >0 THEN
RETURN QUNTITY_FOR_A_PROJECT_;
ELSE
RETURN 0;
END IF;
END EXE14;
END;
错误(6,1):PLS-00103:遇到以下其中一项时遇到符号“QUNTITY_FOR_A_PROJECT_”:语言
答案 0 :(得分:2)
只有对函数或其签名的引用 - 函数名称和参数列表 - 必须在包规范中。实际的功能必须在体内编码。
CREATE OR REPLACE PACKAGE DINIDU_EXE_PACKAGE AS
FUNCTION EXE14
( SUP_ID_ SUPPLIER_PART_PROJECT_TAB.SUPPLIER_ID%TYPE
, PAR_ID_ SUPPLIER_PART_PROJECT_TAB.PART_ID%TYPE
,PRO_ID_ SUPPLIER_PART_PROJECT_TAB.PROJECT_ID%TYPE)
END;
/
CREATE OR REPLACE PACKAGE BODY DINIDU_EXE_PACKAGE AS
FUNCTION EXE14
( SUP_ID_ SUPPLIER_PART_PROJECT_TAB.SUPPLIER_ID%TYPE
, PAR_ID_ SUPPLIER_PART_PROJECT_TAB.PART_ID%TYPE
,PRO_ID_ SUPPLIER_PART_PROJECT_TAB.PROJECT_ID%TYPE)
RETURN NUMBER IS
QUNTITY_FOR_A_PROJECT_ NUMBER;
BEGIN
SELECT QUENTITY AS QUNTITY_FOR_A_PROJECT_ FROM SUPPLIER_PART_PROJECT_TAB WHERE SUPPLIER_ID=SUP_ID AND PART_ID=PAR_ID AND PRO_ID=PROJECT_ID;
IF QUNTITY_FOR_A_PROJECT_ >0 THEN
RETURN QUNTITY_FOR_A_PROJECT_;
ELSE
RETURN 0;
END IF;
END EXE14;
END;
/
答案 1 :(得分:1)
编辑:请参阅Egor的评论和Rachcha对编译错误的实际原因的回答。
您的代码首先将QUNTITY_FOR_A_PROJECT_
声明为局部变量,但随后您的SELECT
语句使用与列别名(QUENTITY AS QUNTITY_FOR_A_PROJECT_
)相同的标识符。更重要的是,您尚未选择结果INTO
任何内容。
我认为你打算做这样的事情:
SELECT QUENTITY INTO QUNTITY_FOR_A_PROJECT_ FROM SUPPLIER_PART_PROJECT_TAB ...
另一个问题:您的函数接受以下参数:SUP_ID_
,PAR_ID_
和PRO_ID_
,但您不在函数中使用它们。我怀疑标识符在查询中没有正确使用,但我无法确定,因为我不知道SUPPLIER_PART_PROJECT_TAB
表的列是什么。