在 Oracle PL/SQL 中,我想测试睡眠功能。我正在使用 hr 模式。但它给了我错误:
PLS-00201: identifier 'DBMS_LOCK' must be declared
代码:
begin
DBMS_LOCK.Sleep( 60 );
end;
/
您应该将该包上的执行权限授予您的架构
grant execute on <object> to <user>;
例如
connect as sys
grant execute on SYS.DBMS_LOCK to someuser;
如果您无权访问 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