ITPub博客

首页 > 数据库 > 数据库开发技术 > DB2 PL/SQL Example: Sleep Procedure

DB2 PL/SQL Example: Sleep Procedure

数据库开发技术 作者:fjzcau 时间:2015-03-28 18:20:01 0 删除 编辑
Sometimes it's useful to have the possibility to suspend a session for a specific time.
In other languages like Java, C, Shell, etc. is a sleep command available.
But as default there's no sleep command in DB2.
However it's very simple to create a stored procedure with exacly this behaviour:


db2 -td@ "create procedure s1.sleep (in sleeptime integer)
begin
  declare wait_until timestamp;

  set wait_until = (current timestamp + sleeptime seconds);
  while (wait_until > current timestamp)
    do
    end while;
end
@
"

Another option is to wait to a specific timestamp:

create procedure sleep_until (in sleepuntil_timestamp timestamp)
begin
  while (sleepuntil_timestamp > current timestamp)
   do
   end while;
end!

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/22661144/viewspace-1477097/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: mbdb1_backup.sh
请登录后发表评论 登录
全部评论

注册时间:2011-04-03

  • 博文量
    208
  • 访问量
    547143