标签:begin rtti cat oca ted dea fetch open diff
--创建存储过程执行删除操作
ALTER PROCEDURE [dbo].[ad_preempted_timer]
AS
DECLARE @pid VARCHAR(32)
DECLARE @times date
DECLARE @nowtime date
DECLARE @difftime INT
--定义一个游标
declare preempted_timer cursor for SELECT pid,inserttime from ad_preempted
--打开游标
open preempted_timer
--开始遍历,将下一行的数据存入两个变量中
fetch next from preempted_timer INTO @pid,@times
while @@fetch_status=0 --如果下一行还有数据
begin
--读取游标
set @nowtime=GETDATE()
SET @difftime=DATEDIFF("hh",@times,@nowtime)
if(@difftime>72)
BEGIN
DELETE from ad_preempted where pid=@pid
END
fetch next from preempted_timer INTO @pid,@times
end
close preempted_timer
--摧毁游标
deallocate preempted_timer
标签:begin rtti cat oca ted dea fetch open diff
原文地址:https://www.cnblogs.com/94LH-shuai/p/9441816.html