zoukankan      html  css  js  c++  java
  • 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.
  • 相关阅读:
    P4068 [SDOI2016]数字配对
    牛客挑战赛43 集合操作
    codefoces 1393D Rarity and New Dress
    codefoces 1400E Clear the Multiset
    [TJOI2017]城市 树形dp
    codefoces 1407E Egor in the Republic of Dagestan
    codefoces 1407D Discrete Centrifugal Jumps
    java保留两位小数(四舍五入和非四舍五入)
    JAVA在命令行进行输入输出重定向(JAVA SentinelValue)
    分治法(排列问题)
  • 原文地址:https://www.cnblogs.com/bicewow/p/12418983.html
Copyright © 2011-2022 走看看