Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: CREATE PACKAGE BODY

Re: CREATE PACKAGE BODY

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: Tue, 04 May 1999 22:55:07 GMT
Message-ID: <373079ca.32700711@192.86.155.100>


A copy of this was sent to mcui_at_cc.usu.edu (if that email address didn't require changing) On 4 May 99 15:15:53 MDT, you wrote:

>I copied a package definition from Oracle server shown below. But
> the package body always has compilation error. Can somebody tell
>me what is wrong with my script? If no error, what can be the cause
>of compilation error.

the example is not syntactically correct -- lose the begin on line 2.

A package body has the syntax:

create or replace package body PKG_NAME as

    <variable definitions>

    functions | procedures
    functions | procedures....

begin

    <some code>
end;
/

the corrected package spec and body might be:

 create or replace package lock_100_to_200 is

   nl_mode  constant integer := 1;
   ss_mode  constant integer := 2;
   sx_mode  constant integer := 3;
   s_mode   constant integer := 4;
   ssx_mode constant integer := 5;

   x_mode constant integer := 6;
   maxwait constant integer := 32767;
   function request(id in integer,
                    lockmode in integer default x_mode,
                    timeout in integer default maxwait,
                    release_on_commit in boolean default FALSE)
     return integer;
   function convert(id in integer,
                    lockmode in integer,
                    timeout in number default maxwait)
     return integer;

   function release(id in integer) return integer;  end;
/
 create or replace package body lock_100_to_200 is    function request(id in integer,
                    lockmode in integer default x_mode,
                    timeout in integer default maxwait,
                    release_on_commit in boolean default FALSE)
     return integer is
   begin
     if id < 100 or id > 200 then
       raise_application_error(-20000,'Lock id out of range');
     end if;
     return dbms_lock.request(id, lockmode, timeout, release_on_commit);
   end;
   function convert(id in integer,
                    lockmode in integer,
                    timeout in number default maxwait)
     return integer is
   begin
     if id < 100 or id > 200 then
       raise_application_error(-20000,'Lock id out of range');
     end if;
     return dbms_lock.convert(id, lockmode, timeout);
   end;
   function release(id in integer) return integer is    begin
     if id < 100 or id > 200 then
       raise_application_error(-20000,'Lock id out of range');
     end if;
     return dbms_lock.release(id);

   end;
 end;
/

>
>SQLWKS> CREATE OR REPLACE package body lock_1_to_200 AS
> 2> begin
> 3> function request(id in integer,
> 4> lockmode in integer default x_mode,
> 5> timeout in integer default maxwait,
> 6> release_on_commit in boolean default FALSE)
> 7> return integer
> 8> AS
> 9> begin
> 10> if id < 1 or id > 200 then
> 11> raise_application_error(-20000,'Lock id out of range');
> 12> endif;
> 13> return dbms_lock.request(id, lockmode, timeout,
>release_on_commit);
> 14> end request;
> 15> function convert(id in integer,
> 16> lockmode in integer,
> 17> timeout in number default maxwait)
> 18> return integer
> 19> AS
> 20> begin
> 21> if id < 1 or id > 200 then
> 22> raise_application_error(-20000,'Lock id out of range');
> 23> endif;
> 24> return dbms_lock.convert(id, lockmode, timeout);
> 25> end convert;
> 26> function release(id in integer) return integer
> 27> AS
> 28> begin
> 29> if id < 1 or id > 200 then
> 30> raise_application_error(-20000,'Lock id out of range');
> 31> endif;
> 32> return dbms_lock.release(id);
> 33> end release;
> 34> end lock_1_to_200 ;
> 35>
>MGR-00072: Warning: PACKAGE BODY LOCK_1_TO_200 created with compilation errors.
>
>error from Oracle schema manager:
>
>PLS-00103: Encounted the symbol"REQUEST" when expecting one of the following:
>:= . [ @ %;
> The symbol ":=" was substituted for "REQUEST" to continue.
>
>PLS-00103: Encounted the symbol"DEFAULT" when expecting one of the following:
>:= . [ @ % - + mod rem.
> an exponent[**] and or ||;
> The symbol "." was inserted before "DEFAULT" to continue.
>

See http://www.oracle.com/ideveloper/ for my column 'Digging-in to Oracle8i'...  

Thomas Kyte
tkyte_at_us.oracle.com
Oracle Service Industries
Reston, VA USA

--
Opinions are mine and do not necessarily reflect those of Oracle Corporation Received on Tue May 04 1999 - 17:55:07 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US