raise application error Trigger in MySQL DBMS

2020-07-18 09:06发布

I am dealing with triggers in MySQL, and I want to add the raise application error, but my code indicates :

Error code 1064, SQL state 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 '(-20000,'Pay is below Texas minimum wage!');

END IF;

END' at line 9

and if I remove the part of raise application error, it works perfectly .

Trigger:

DELIMITER @@
DROP TRIGGER IF EXISTS gmtt.after_update_mcorr @@

CREATE TRIGGER gmtt.after_update_mcorr
AFTER UPDATE ON gmtt.mcorr
FOR EACH ROW
BEGIN
       IF OLD.etat = '0' AND NEW.etat = '1' THEN
            INSERT INTO historique(message, User, dateHisto) VALUES (CONCAT( 'a achevé la Maintenance ', OLD.codeMaint) , CURRENT_USER(), NOW()); 
       ELSE
raise_application_error(-20000,'Pay is below Texas minimum wage!');     

    END IF;

    END @@ 
DELIMITER ;

1条回答
淡お忘
2楼-- · 2020-07-18 09:40

Your syntax appears to be MySQL. And yet, raise_application_error is an Oracle construct. You want signal, documented here:

DELIMITER @@
DROP TRIGGER IF EXISTS gmtt.after_update_mcorr @@
CREATE TRIGGER gmtt.after_update_mcorr
AFTER UPDATE ON gmtt.mcorr
FOR EACH ROW
BEGIN
   IF OLD.etat = '0' AND NEW.etat = '1' THEN
        INSERT INTO historique(message, User, dateHisto)
             VALUES (CONCAT( 'a achevé la Maintenance ', OLD.codeMaint) , CURRENT_USER(), NOW()); 
   ELSE
       signal sqlstate '-20000' set message_text = 'Pay is below Texas minimum wage!';     
   END IF;
END @@ 
DELIMITER ;
查看更多
登录 后发表回答