oracle pl / sql DBMS_LOCK错误

时间:2012-06-03 13:32:57

标签: oracle plsql

在Oracle PL / SQL中,我想测试睡眠功能。我正在使用hr架构。但它给了我错误:

PLS-00201: identifier 'DBMS_LOCK' must be declared

代码:

begin
 DBMS_LOCK.Sleep( 60 );
end;
/

2 个答案:

答案 0 :(得分:21)

您应该将grant execute打包到您的架构

grant execute on <object> to <user>;

e.g。

connect as sys
grant execute on SYS.DBMS_LOCK to someuser;

答案 1 :(得分:1)

如果您无权访问sys或dba不愿意这样做

   GRANT EXECUTE on SYS.DBMS_LOCK to you;

您可以在数据库中创建Java过程:

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

并创建一个函数,该函数调用java存储过程

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

之后
GRANT EXECUTE ON sleep TO public;

您可以通过选择

拨打电话
select sleep(6000) from dual