意外的令牌“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;
请帮帮我,它给出了错误
please help me it's give errors
意外的标记CREATE TRIGGER TRG_EFMREFNO
在BEGIN-OF-STATEMENT"之后发现 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
请给出该错误的解决方案
Please give the solution for that errors
推荐答案
这里发生了两件事 -
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@
或者如果你想从文件中读取
or if you want to read from a file
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屋!