首页 > 代码库 > oracle DBMS_LOCK.SLEEP()的使用

oracle DBMS_LOCK.SLEEP()的使用

create or replace procedure times is
ii positive:=1;
begin
loop
dbms_lock.sleep(1);
dbms_output.put_line(ii||‘ ‘||to_char(sysdate,‘yyyy-mm-dd hh24:mi:ss‘));
ii:=ii+1;
exit when ii>10;
end loop;
end;
/

 结果:

SQL> exec times;
1 2016-10-08 11:26:57
2 2016-10-08 11:26:58
3 2016-10-08 11:26:59
4 2016-10-08 11:27:00
5 2016-10-08 11:27:01
6 2016-10-08 11:27:02
7 2016-10-08 11:27:03
8 2016-10-08 11:27:04
9 2016-10-08 11:27:05
10 2016-10-08 11:27:06

PL/SQL 过程已成功完成。

oracle DBMS_LOCK.SLEEP()的使用