Mysql触发器在我的触发器上抛出语法错误

时间:2015-01-25 17:27:58

标签: mysql syntax triggers

执行时,触发器会抛出以下错误。请帮忙

DELIMITER |
CREATE  TRIGGER `Problem_created` AFTER UPDATE  ON `WorkOrder_Fields` FOR EACH ROW
BEGIN
DECLARE problem_time_stamp   int;


IF   NEW.UDF_CHAR37 ='Problem'  AND  OLD.UDF_CHAR37='Incident'

    THEN

        SET problem_time_stamp    = (SELECT UNIX_TIMESTAMP(now())*1000);

        update workorder_fields set UDF_DATE6=problem_time_stamp    where WORKORDERID=OLD.WORKORDERID ;

    END IF;
END |
DELIMITER ;

=============================================== =========================

[root@vmesx42s32 bin]#  mysql -u root -S../tmp/mysql.sock supportcenter
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 263 to server version: 4.1.18-pro

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> DELIMITER |
mysql> CREATE  TRIGGER `Problem_created` AFTER UPDATE  ON `WorkOrder_Fields` FOR EACH ROW
    -> BEGIN
    -> DECLARE problem_time_stamp   int;
    ->
->
    -> IF   NEW.UDF_CHAR37 ='Problem'  AND  OLD.UDF_CHAR37='Incident'

IF   NEW.UDF_CHAR37 ='Problem'  AND  OLD.UDF_CHAR37='Incident'
    ->
 -> THEN
    ->
     ->  SET problem_time_stamp    = (SELECT UNIX_TIMESTAMP(now())*1000);
 ->

        -> update workorder_fields set UDF_DATE6=problem_time_stamp    where WORKORDERID=OLD.WORKORDERID ;
 ->
    -> END IF;
 -> END |
**ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near     'TRIGGER `Problem_created` AFTER UPDATE  ON `WorkOrder_Fields` FOR EACH ROW
BEGIN' at line 1**
mysql> DELIMITER ;

1 个答案:

答案 0 :(得分:1)

您通常不想对触发器修改的表进行更新。而是执行before insert触发器和:

IF   NEW.UDF_CHAR37 ='Problem'  AND  OLD.UDF_CHAR37='Incident'
THEN
    SET new.UDF_DATE6 := UNIX_TIMESTAMP(now())*1000);  
END IF;

这假定WORKORDERID未更新,但根据其名称,这似乎不太可能。