Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: CREATE PACKAGE BODY
Hi Muyi,
You just had couple of sintax errors,
here I fixed them and it works:
drop package lock_1_to_200 ;
create package lock_1_to_200 AS
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;
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;
drop package body lock_1_to_200;
CREATE OR REPLACE package body lock_1_to_200 AS
-- begin
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 AS begin if id < 1 or id > 200 then raise_application_error(-20000,'Lock id out of range'); -- endif; end if; return dbms_lock.request(id, lockmode, timeout, release_on_commit); end request; function convert(id in integer, lockmode in integer, timeout in number default maxwait) return integer AS begin if id < 1 or id > 200 then raise_application_error(-20000,'Lock id out of range'); -- endif; end if; return dbms_lock.convert(id, lockmode, timeout); end convert;
begin if id < 1 or id > 200 then raise_application_error(-20000,'Lock id out of range'); -- endif; end if; return dbms_lock.release(id); end release;
ALL ERRORS ARE REMED OUT (--) AND CORRECTION IS MADE AFTER THEM Good Luck!
+--------------------------------------------------------------------------+
|
+--------------------------------------------------------------------------+
-----Original Message-----
From: Muyi Cui [mailto:MCui_at_Dentrix.com]
Sent: Tuesday, May 04, 1999 2:33 PM
To: 'vit100gain_at_earthlink.net'
Subject: Help on package and build-in functions
Dear Vitaliy,
Thanks for the good advice you posted on the net. I have two questions.
Hope you can help me.
1. I tried to create a package called lock_1_to_200 in Oracle. I run the
script as SYS.
The script is as follows:
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;
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;
drop package body lock_1_to_200;
CREATE OR REPLACE package body lock_1_to_200 AS
begin
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 AS begin if id < 1 or id > 200 then raise_application_error(-20000,'Lock id out of range'); endif; return dbms_lock.request(id, lockmode, timeout, release_on_commit); end request; function convert(id in integer, lockmode in integer, timeout in number default maxwait) return integer AS begin if id < 1 or id > 200 then raise_application_error(-20000,'Lock id out of range'); endif; return dbms_lock.convert(id, lockmode, timeout); end convert;
begin if id < 1 or id > 200 then raise_application_error(-20000,'Lock id out of range'); endif; return dbms_lock.release(id); end release;
I ran the script. The create package body body has compilation error as follows:
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 ;
I then used schema manager to recompile it and I still got these errors:
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.
Do you know what is happening?
2. I tried to call a build-in function (request) in DBMS_LOCK package. I ran
the script as user sys.
select dbms_lock.request(2,2,2,FALSE) from dual;
It gave me this error:
2>
select dbms_lock.request(2,2,2,FALSE) from dual
*
I would appreciate any advice.
Thanks.
Muyi Cui
Software Engineer and DBA
Dentrix Inc
mcui_at_cc.usu.edu 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. > > 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.Received on Tue May 04 1999 - 17:13:58 CDT
![]() |
![]() |