您好我正在尝试编写DB2过程,这在SQL Server中是一个简单的任务,但在DB2中看起来非常困难
脚本:
CREATE PROCEDURE TT.PURGE_LOGS ()
LANGUAGE SQL
SPECIFIC atomic_proc
ap: BEGIN ATOMIC
DELETE FROM TT.DTL
WHERE LOGID IN
(SELECT LOGID FROM TT.HDR
WHERE LOGTYPE <> 120 AND CRDATE < CURRENT_DATE - 30 DAY FROM sysibm.sysdummy1);
SIGNAL SQLSTATE '70000';
DELETE LOGID FROM TT.HDR
WHERE LOGTYPE <> 120 AND CRDATE < CURRENT_DATE - 30 DAY FROM sysibm.sysdummy1;
END ap
错误: SQL错误[42601]:[SQL0199]关键字FROM不期望。有效令牌:使用SKIP WAIT WITH WHERE
我出错的任何想法?
答案 0 :(得分:0)
正如mustaccio在评论中已经建议的那样,您的语法无效。
如果CRDATE的数据类型是DATE那么你的意思是:
CREATE or replace PROCEDURE TT.PURGE_LOGS ()
LANGUAGE SQL
SPECIFIC atomic_proc
ap:
BEGIN ATOMIC
DELETE FROM TT.DTL
WHERE LOGID IN
(SELECT LOGID
FROM TT.HDR
WHERE LOGTYPE <> 120
AND CRDATE < CURRENT_DATE - 30 DAYS
) ;
DELETE FROM TT.HDR
WHERE LOGTYPE <> 120
AND CRDATE < CURRENT DATE - 30 DAYS
;
END ap
请注意,您的SIGNAL SQLSTATE
应该位于异常处理程序中,否则在编写时其目的不明确。