Oracle 18C中DBMS_SESSION.SLEEP和DBMS_LOCK.SLEEP推荐使用那个?
作者:互联网
介绍
在 18c 中不推荐使用 DBMS_LOCK.SLEEP,推荐使用 DBMS_SESSION.SLEEP,并且无需额外授权即可使用。
SLEEP会将会话暂停指定的秒数。
实践证明
SQL> select * from user_role_privs; USERNAME GRANTED_RO ADMIN_OPTI DELEGATE_O DEFAULT_RO OS_GRANTED COMMON INHERITED ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- TEST CONNECT NO NO YES NO NO NO TEST RESOURCE NO NO YES NO NO NO SQL> show user USER is "TEST" SQL> SET SERVEROUTPUT ON ; SQL> BEGIN 2 DBMS_OUTPUT.PUT_LINE('Start ' || to_char(SYSDATE, 'YYYY-MM-DD HH24:MI:SS')); 3 dbms_session.sleep(5); 4 DBMS_OUTPUT.PUT_LINE('End ' || to_char(SYSDATE, 'YYYY-MM-DD HH24:MI:SS')); 5 END; 6 / Start 2020-03-05 10:49:36 End 2020-03-05 10:49:41 PL/SQL procedure successfully completed.
默认情况下无法使用 DBMS_LOCK,必须为用户授予 dbms_lock 包的执行权限。DBMS_SESSION.SLEEP 不需要任何额外授权。
如果在使用DBMS_SESSION.SLEEP时指定的值大于3600,则会得到“ORA-38148:指定的时间限制无效”。
DBMS_LOCK.SLEEP过程不会报此错误。
SQL> EXEC DBMS_SESSION.sleep(3601); BEGIN DBMS_SESSION.sleep(3601); END; * ERROR at line 1: ORA-38148: invalid time limit specified ORA-06512: at "SYS.DBMS_SYS_ERROR", line 79 ORA-06512: at "SYS.DBMS_SESSION", line 432 ORA-06512: at line 1 SQL> !oerr ora 38148 38148, 00000, "invalid time limit specified" // *Cause: Specified time limit value was not a positive integer. // *Action: Specify a positive integer value. SQL> EXEC DBMS_LOCK.sleep(3601); PL/SQL procedure successfully completed.
标签:18C,DBMS,NO,LOCK,SESSION,SLEEP,SQL 来源: https://www.cnblogs.com/bicewow/p/12418983.html