Error: PLS-00103: Encountered the symbol ")" when expecting one of the following

Error: PLS-00103: Encountered the symbol ")" when expecting one of the following

当我在 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;

您有几个错误:

首先,像在包体中一样去掉括号。由于该函数没有任何参数,因此您不需要它们。其次,确保规范中的 return 类型与您在正文中使用的类型相同,在这种情况下,您应该使用 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;