Sleep function in ORACLE

后端 未结 11 1914
一整个雨季
一整个雨季 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条回答
  •  清歌不尽
    2020-11-30 01:20

    Short of granting access to DBMS_LOCK.sleep, this will work but it's a horrible hack:

    IN_TIME INT; --num seconds
    v_now DATE;
    
    -- 1) Get the date & time 
    SELECT SYSDATE 
      INTO v_now
      FROM DUAL;
    
    -- 2) Loop until the original timestamp plus the amount of seconds <= current date
    LOOP
      EXIT WHEN v_now + (IN_TIME * (1/86400)) <= SYSDATE;
    END LOOP;
    

提交回复
热议问题