pl/sql 包体中的错误

error in pl/sql package body

我有这个错误:

错误(42,22):PLS-00103:在期望以下之一时遇到符号“)”:当前

我写了一个功能和程序很少的包。

这是我的包裹:

-- specification --

CREATE OR REPLACE PACKAGE SUPERHERO_PACKAGE AS

FUNCTION GET_FULL_SUPERHERONAME(V_SUPERHERONAME IN VARCHAR2)
    RETURN VARCHAR2;
PROCEDURE GET_SUPERHEROS(V_CITY IN VARCHAR2);
PROCEDURE GET_ALL_VILLANS;
FUNCTION GET_MAX_XP
    RETURN NUMBER;
FUNCTION GET_STRONGEST_SUPERHERO
    RETURN VARCHAR2;

END SUPERHERO_PACKAGE;

-- body --

CREATE OR REPLACE PACKAGE BODY SUPERHERO_PACKAGE AS 

FUNCTION GET_FULL_SUPERHERONAME(V_SUPERHERONAME IN VARCHAR2)
    RETURN VARCHAR2 AS
        BEGIN
            SELECT FIRST_NAME, LAST_NAME 
            INTO V_FNAME, V_LNAME
            FROM SUPERHERO
            WHERE SUPERHERO_NAME = V_SUPERHERONAME;

            RETURN (V_FNAME || " " || V_LNAME);
        END;

PROCEDURE GET_SUPERHEROS(V_CITY IN VARCHAR2) IS
            CURSOR JUSTICE_LEAGUE IS
            SELECT SUPERHERO_NAME FROM SUPERHERO WHERE CITY = V_CITY;
            LEAGUE_MEMBER JUSTICE_LEAGUE % ROWTYPE;
        BEGIN
            OPEN JUSTICE_LEAGUE;
            LOOP 
                FETCH JUSTICE_LEAGUE INTO LEAGUE_MEMBER;
                EXIT WHEN (JUSTICE_LEAGUE % NOTFOUND);
                DBMS_OUTPUT.PUT_LINE(LEAGUE_MEMBER.NAME);
            END LOOP;
            CLOSE JUSTICE_LEAGUE;
        END;

PROCEDURE GET_ALL_VILLANS IS
            CURSOR DARK_FORCE IS
            SELECT VILLAN FROM SUPERHERO;
            FORCE_MEMBER DARK_FORCE % ROWTYPE;
        BEGIN
            OPEN DARK_FORCE;
            LOOP
            FETCH DARK_FORCE INTO FORCE_MEMBER;
            EXIT WHEN (DARK_FORCE % NOTFOUND);
            DBMS_OUTPUT.PUT_LINE(FORCE_MEMBER.VILLAN);
            END LOOP;
            CLOSE DARK_FORCE;
        END;

FUNCTION GET_MAX_XP()
    RETURN NUMBER AS
        DECLARE
            N_XP := 0;
        BEGIN
            SELECT MAX(XP) INTO N_XP FROM SUPERHERO;
            RETURN N_XP;
        END;

FUNCTION GET_STRONGEST_SUPERHERO()
    RETURN VARCHAR2 AS
        DECLARE 
            V_NAME := 'DNA';
            V_FNAME := 'SWAYAM';
            V_LNAME := 'RAINA';
        BEGIN
            SELECT SUPERHERO_NAME, FIRST_NAME, LAST_NAME
            INTO V_NAME, V_FNAME, V_LNAME
            FROM SUPERHERO
            WHERE XP = GET_MAX_XP();
            RETURN (V_FNAME || " " || V_LNAME || " AKA " || V_NAME);
        END;

END SUPERHERO_PACKAGE;

你的代码错误百出。请检查下面的更正。

CREATE OR REPLACE PACKAGE SUPERHERO_PACKAGE
AS
   FUNCTION GET_FULL_SUPERHERONAME (V_SUPERHERONAME IN VARCHAR2)  RETURN VARCHAR2;

   PROCEDURE GET_SUPERHEROS (V_CITY IN VARCHAR2);

   PROCEDURE GET_ALL_VILLANS;

   FUNCTION GET_MAX_XP  RETURN NUMBER;

   FUNCTION GET_STRONGEST_SUPERHERO RETURN VARCHAR2;
END SUPERHERO_PACKAGE;

-- body --

CREATE OR REPLACE PACKAGE BODY SUPERHERO_PACKAGE
AS
   FUNCTION GET_FULL_SUPERHERONAME (V_SUPERHERONAME IN VARCHAR2)
    RETURN VARCHAR2 AS
    V_FNAME varchar2(1000); 
    V_LNAME varchar2(1000);

   BEGIN
      SELECT FIRST_NAME, LAST_NAME
        INTO V_FNAME, V_LNAME
        FROM SUPERHERO
       WHERE SUPERHERO_NAME = V_SUPERHERONAME;

      RETURN(V_FNAME||'--'||V_LNAME);
   END;

   PROCEDURE GET_SUPERHEROS (V_CITY IN VARCHAR2)
   IS
      CURSOR JUSTICE_LEAGUE(vr_city VARCHAR2)  --- parameterized Query
      IS
         SELECT SUPERHERO_NAME
           FROM SUPERHERO
          WHERE CITY = vr_city;

      LEAGUE_MEMBER  JUSTICE_LEAGUE%ROWTYPE;
   BEGIN
      OPEN JUSTICE_LEAGUE(V_CITY);  --This is the way to call.

      LOOP
         FETCH JUSTICE_LEAGUE INTO LEAGUE_MEMBER;

         EXIT WHEN JUSTICE_LEAGUE%NOTFOUND;  -- No brackets needed

         DBMS_OUTPUT.PUT_LINE(LEAGUE_MEMBER.SUPERHERO_NAME);

      END LOOP;

      CLOSE JUSTICE_LEAGUE;
   END;

   PROCEDURE GET_ALL_VILLANS
   IS
      CURSOR DARK_FORCE
      IS
         SELECT VILLAN 
        FROM SUPERHERO;

      FORCE_MEMBER   DARK_FORCE%ROWTYPE;
   BEGIN
      OPEN DARK_FORCE;

      LOOP
         FETCH DARK_FORCE INTO FORCE_MEMBER;

         EXIT WHEN DARK_FORCE%NOTFOUND;

         DBMS_OUTPUT.PUT_LINE (FORCE_MEMBER.VILLAN);

      END LOOP;

      CLOSE DARK_FORCE;
   END;

   FUNCTION GET_MAX_XP
      RETURN NUMBER
   AS
    N_XP number:= 0;          --Never use declare here 
   BEGIN
      SELECT MAX (XP) INTO N_XP FROM SUPERHERO;

      RETURN N_XP;
   END;

   FUNCTION GET_STRONGEST_SUPERHERO 
      RETURN VARCHAR2
   AS
      V_NAME  varchar2(1000)  := 'DNA';                  --------Declaration Missing
      V_FNAME varchar2(1000)  := 'SWAYAM';
      V_LNAME varchar2(1000)  := 'RAINA';
   BEGIN
      SELECT SUPERHERO_NAME, FIRST_NAME, LAST_NAME
        INTO V_NAME, V_FNAME, V_LNAME
        FROM SUPERHERO
       WHERE XP = (SELECT GET_MAX_XP() from dual);  ----general practrice to call a function in where clause

      RETURN (V_FNAME||' '||V_LNAME||'AKA'||V_NAME); --no double quotes
   END;
END SUPERHERO_PACKAGE;