我正在创建一个DB2触发器:
CREATE TRIGGER updateExternalServiceTrigger
AFTER INSERT ON ABS_EXTERNAL_SERVICES
REFERENCING NEW AS N
FOR EACH ROW MODE DB2ROW
UPDATE OF REQ_STAN WHEN REQ_TYPE='FT'
BEGIN ATOMIC
UPDATE ABS_EXTERNAL_SERVICES
SET REQ_STAN= nextval of SEQ_ID_HOST_STAN
WHERE ID_EXTERNAL_SERVICE = N.ID_EXTERNAL_SERVICE and REQ_TYPE='FT';
END
但是我收到了这个错误:
Error report:
DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=MODE DB2ROW
UPDATE OF REQ_STAN WHEN REQ_;AS N
FOR EACH ROW;<from>, DRIVER=3.69.66
任何人都可以帮我创建此触发器吗?
答案 0 :(得分:0)
您的意思是使用before-insert触发器有条件地设置req_stan列吗?:
create trigger beft1
before insert on abs_external_services
referencing new as N
for each row mode db2sql
begin atomic
if n.req_type ='FT'
then
set n.req_stan = nextval for seq_id_host_stan;
end if;
end
您的after insert
语法有两个错误(a)模式db2row无效(模式db2sql有效),以及(b)您似乎有一个注释注释显示为第一次引用更新的代码UPDATE OF REQ_STAN WHEN REQ_TYPE='FT'
。所有的dml都必须在BEGIN之后。