Sleep function in ORACLE

后端 未结 11 1909
一整个雨季
一整个雨季 2020-11-30 00:52

I need execute an SQL query in ORACLE it takes a certain amount of time. So I wrote this function:

CREATE OR REPLACE FUNCTION MYSCHEMA.TEST_SLEEP
(
TIME_  I         


        
11条回答
  •  Happy的楠姐
    2020-11-30 01:00

    From Oracle 18c you could use DBMS_SESSION.SLEEP procedure:

    This procedure suspends the session for a specified period of time.

    DBMS_SESSION.SLEEP (seconds  IN NUMBER)
    

    DBMS_SESSION.sleep is available to all sessions with no additional grants needed. Please note that DBMS_LOCK.sleep is deprecated.

    If you need simple query sleep you could use WITH FUNCTION:

    WITH FUNCTION my_sleep(i NUMBER)
    RETURN NUMBER
    BEGIN
        DBMS_SESSION.sleep(i);
        RETURN i;
    END;
    SELECT my_sleep(3) FROM dual;
    

提交回复
热议问题