当我在PL / SQL开发人员中按F8创建Package MyPackage时,我得到以下错误
Error: PLS-00103: Encountered the symbol ")" when expecting one of the following:
<an identifier> <a double-quoted delimited-identifier>
current delete exists prior
Line: 24
Text: FUNCTION MyFunction() RETURN VARCHAR;
以下是代码
CREATE OR REPLACE PACKAGE MyPackage AS
FUNCTION MyFunction() RETURN VARCHAR;
END MyPackage;
CREATE OR REPLACE PACKAGE BODY MyPackage AS
FUNCTION MyFunction RETURN VARCHAR2 IS
l_pram mytable.param_val%TYPE;
BEGIN
SELECT SomeColumnVal INTO l_pram FROM mytable WHERE SomeColumn = 'SomeValue';
RETURN l_pram;
END MyFunction;
END MyPackageBody;
答案 0 :(得分:1)
您有几个错误:
首先,只需像在包体中那样删除括号。由于该函数没有任何参数,因此您不需要它们。其次,确保规范中的返回类型与您在正文中使用的返回类型相同,在这种情况下,您应该使用VARCHAR2
CREATE OR REPLACE PACKAGE MyPackage AS
FUNCTION MyFunction RETURN VARCHAR2;
END MyPackage;
最后,包体中的结束名称应与您在规范中使用的名称相同,即MyPackage而不是MyPackageBody
CREATE OR REPLACE PACKAGE BODY MyPackage AS
FUNCTION MyFunction RETURN VARCHAR2 IS
l_pram mytable.param_val%TYPE;
BEGIN
SELECT SomeColumnVal INTO l_pram FROM mytable WHERE SomeColumn = 'SomeValue';
RETURN l_pram;
END MyFunction;
END MyPackage;