我正在尝试使用触发器更新另一个表。这是我的代码:
CREATE TRIGGER REORDER
AFTER UPDATE OF ON_HAND
REFERENCING NEW AS N
FOR EACH ROW
WHEN (N.ON_HAND < 0.1)
BEGIN ATOMIC
UPDATE SRI set SRI.price = SRI.price*10 where SRI.CODE = N.CODE;
END
我收到以下错误:
在“CODE =”之后发现意外的标记“END-OF-STATEMENT” N.CODE“。预期的代币可能包括:”“.. SQLCODE = -104,SQLSTATE = 42601,DRIVER = 3.68.61
答案 0 :(得分:0)
以下脚本化请求,显示设置,然后是两个失败的请求和一个成功的请求;第一个CREATE TRIGGER与OP的格式和触发器的命名方式基本相同,其余两个是其次要修订的结果:
设定:
ExternalProject_Add
几个CREATE TRIGGER请求;完整的触发器名称用于解释从先前迭代中创建的有效mod,并且每个请求之后的注释描述了运行IBM DB2 for i 7.1的经验结果:
create table on_hand_table (code char, on_hand dec(3, 1) )
; -- Table ON_HAND_TABLE created
create table sri (code char, price dec(7, 2) )
; -- Table SRI created
create trigger ReOrder_source_unchanged
after update of ON_HAND
referencing NEW as N
for each row
when (N.ON_HAND < 0.1 )
begin ATOMIC
UPDATE SRI
set SRI.price = SRI.price*10
WHERE SRI.code = N.code
;
end
-- Keyword REFERENCING not expected. Valid tokens: ON OR.
create trigger ReOrder_OF_Changed_to_ON
after update on ON_HAND
referencing NEW as N
for each row
when (N.ON_HAND < 0.1 )
begin ATOMIC
UPDATE SRI
set SRI.price = SRI.price*10
WHERE SRI.code = N.code
;
end
-- Table ON_HAND not found.
答案 1 :(得分:-1)
OP中给出的CREATE TRIGGER似乎缺少ON table-reference
;仅编码OF column-name
。可能是问题的根源,虽然有一个奇怪的位置被诊断出来的语法问题。?
create trigger ReOrder
after update of ON_HAND /* this names the column being updated */
on ON_HAND_TABLE /* this is missing from OP */
referencing NEW as N
…