意外的令牌“CREATE TRIGGER” [英] An unexpected token "CREATE TRIGGER
问题描述
CREATE TRIGGER TRG_EFMREFNO
BEFORE
INSERT ON FEEDBACK_CASE_TB
FOR EACH ROW
BEGIN
SELECT SEQ_EFMREFNO.NEXTVAL INTO:NEW.EFMREFNO FROM DUAL;
END;
请帮助我发送错误
BEGIN-OF-STATEMENT发现了一个意外的令牌CREATE TRIGGER TRG_EFMREFNO
BEFOR。预期令牌可能包括:< revoke>
.. SQLCODE = -104,SQLSTATE = 42601,DRIVER = 4.12.79
An unexpected token "CREATE TRIGGER TRG_EFMREFNO
BEFOR" was found following "BEGIN-OF-STATEMENT". Expected tokens may include: "<revoke>
".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.12.79
在END之后找到一个意外的标记END-OF-STATEMENT。预期令牌可能包括:JOIN < joined_table>
.. SQLCODE = -104,SQLSTATE = 42601,DRIVER = 4.12.79
An unexpected token "END-OF-STATEMENT" was found following "END". Expected tokens may include: "JOIN <joined_table>
".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.12.79
请给出错误的解决方案
推荐答案
你有2件事在这里 -
You have 2 things going on here -
1)当;字符是SQL语句的一部分,有必要使用不同的字符来终止语句。我通常使用@。要告诉db2命令您选择了不同的字符,请使用
1) When the ";" character is part of the SQL statement, it's necessary to use a different character to terminate the statement. I typically use "@". To tell the "db2" command that you have chosen a different character, use
db2 -td@
或者要从文件中读取
db2 -td@ -f <somefile>
2)更新触发器新行的正确方法是为新行设置别名,并使用set子句:
2) The correct way to update new row in a trigger is to set an alias for the new row, and use a set clause:
CREATE TRIGGER TRG_EFMREFNO
BEFORE
INSERT ON FEEDBACK_CASE_TB
REFERENCING NEW AS N
FOR EACH ROW
BEGIN
SET N.EFMREFNO = SEQ_EFMREFNO.NEXTVAL;
END
@
可能还有其他方法可以将序列与create table语句中的default子句将完成相同的操作:
There may be other ways to use the sequence with the default clause in the create table statement that will accomplish the same thing:
这篇关于意外的令牌“CREATE TRIGGER”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!