Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

oracle pl/sql DBMS_LOCK error

Tags:

oracle

plsql

In the Oracle PL/SQL, I want to test the sleep function. I am using hr schema. but it gives me error :

PLS-00201: identifier 'DBMS_LOCK' must be declared

code:

begin
 DBMS_LOCK.Sleep( 60 );
end;
/
like image 582
user595234 Avatar asked Jun 03 '12 13:06

user595234


2 Answers

You should grant execute on that package to your schema

grant execute on <object> to <user>;

e.g.

connect as sys
grant execute on SYS.DBMS_LOCK to someuser;
like image 54
archimede Avatar answered Oct 23 '22 15:10

archimede


If you you don't have access to sys or your dba is unwilling to do

   GRANT EXECUTE on SYS.DBMS_LOCK to you;

You can create a Java procedure in the database:

   CREATE OR REPLACE PROCEDURE SLEEPIMPL (P_MILLI_SECONDS IN NUMBER) 
   AS LANGUAGE JAVA NAME 'java.lang.Thread.sleep(long)';

And create a function, which calls the java stored procedure

 CREATE OR REPLACE FUNCTION sleep (
    seconds IN NUMBER
   ) RETURN NUMBER
   AS
   BEGIN
     SLEEPIMPL( seconds );
     RETURN seconds;
   END;

which after a

GRANT EXECUTE ON sleep TO public;

you can call from a select

select sleep(6000) from dual
like image 31
chenrici Avatar answered Oct 23 '22 17:10

chenrici