PLS-00103 while creating 2 packages PLSQL

Politiepet picture Politiepet · Jan 6, 2015 · Viewed 7k times · Source

im trying to create 2 package body's in plsql. This is my code:

SET SERVEROUTPUT ON

CREATE OR REPLACE PACKAGE p_locations
AS
  FUNCTION f_distance(Lat1 IN NUMBER, Lon1 IN NUMBER, Lat2 IN NUMBER, Lon2 IN NUMBER, Radius IN NUMBER DEFAULT 6387.7) return number;
END p_locations;

/

CREATE OR REPLACE PACKAGE BODY p_locations
AS
  FUNCTION f_distance (Lat1 IN NUMBER, Lon1 IN NUMBER, Lat2 IN NUMBER, Lon2 IN NUMBER, Radius IN NUMBER DEFAULT 6387.7)
  RETURN NUMBER 
  IS
   -- Convert degrees to radians
   DegToRad NUMBER := 57.29577951;

  BEGIN
    RETURN(NVL(Radius,0) * ACOS((sin(NVL(Lat1,0) / DegToRad) * SIN(NVL(Lat2,0) / DegToRad)) +
          (COS(NVL(Lat1,0) / DegToRad) * COS(NVL(Lat2,0) / DegToRad) *
           COS(NVL(Lon2,0) / DegToRad - NVL(Lon1,0)/ DegToRad))));
  END f_distance;
END p_locations;

/

CREATE OR REPLACE PACKAGE p_winkel
AS
  FUNCTION changeOpeningstijd("id" IN number) RETURN boolean;
END p_winkel;

/

CREATE OR REPLACE PACKAGE BODY p_winkel
AS
  FUNCTION changeOpeningstijd("id" IN number) 
  RETURN boolean
  IS
    dbms_output.put_line('dit is uitgevoerd');
    return true;
  END changeOpeningstijd;
END p_winkel;

When I run this I gat 3 times a PLS-00103 error. The first is on line 6,16 and says encountered the symbol "." when expecting one of the following: constant exception <an identifier> <a double-quoted delimited-identifier> table long double ref char time timestamp interval date binary national character nchar The symbol "<an identifier>" was substituted for "." to continue.

The strange thing is that when I comment out the 2nd package body everything works fine. Whilst the errors are at the beginning of the first package definition.

Am I doing something stupid wrong here, or can't you create two packages in one session, or what else is going on here, because I don't see any logic in these errors.

Answer

Alex Poole picture Alex Poole · Jan 6, 2015

You're just missing the BEGIN keyword:

CREATE OR REPLACE PACKAGE BODY p_winkel
AS
  FUNCTION changeOpeningstijd("id" IN number) 
  RETURN boolean
  IS
  BEGIN    ---- this was missing
    dbms_output.put_line('dit is uitgevoerd');
    return true;
  END changeOpeningstijd;
END p_winkel;
/

The line number in the PL/SQL error refers to the PL/SQL block (package, in this case) it is caused by; it isn't the line number in your combined script, as would be the case for a plain SQL error.

When you run this with run script you get three errors reported, not just the one you referred to; and the other two both mention begin:

Errors: check compiler log
6/16           PLS-00103: Encountered the symbol "." when expecting one of the following:

   constant exception <an identifier>
   <a double-quoted delimited-identifier> table long double ref
   char time timestamp interval date binary national character
   nchar
The symbol "<an identifier>" was substituted for "." to continue.

8/3            PLS-00103: Encountered the symbol "END" when expecting one of the following:

   begin function pragma procedure subtype type <an identifier>
   <a double-quoted delimited-identifier> current cursor delete
   exists prior
The symbol "begin was inserted before "END" to continue.

9/13           PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:

   begin end function pragma procedure

As Ben mentioned it's a good idea to add a show errors after each spec/body definition to highlight where an error is seen; but you can also query the user_errors view to see the errors related to each invalid object.