Search code examples
mysqlsqltriggersudf

UDF trigger not working MySQL ERROR 1064 (42000)


Here is the code:

DELIMITER @@

CREATE TRIGGER autohome1

AFTER INSERT ON prueba 

DECLARE cmd VARCHAR(255);

SET cmd=CONCAT('sh /home/pi/Desktop/Py_Script_Auto_Home/autohome.sh');

sys_exec(cmd);

@@

DELIMITER ;

So I suspect the error comes from the CONCAT function but I am not sure because I have tried plenty of different options to try and solve it, I have also looked through the questions previously asked about this topic in the forum.

The error I get is the following:

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 'DECLARE cmd VARCHAR(255);
SET cmd=CONCAT('sh /home/pi/Desktop/Py_Script_Auto_Hom' at line 3

Thanks beforehand


Solution

  • DELIMITER @@
    CREATE TRIGGER autohome1 AFTER INSERT ON prueba 
    FOR EACH ROW
    BEGIN
       DECLARE cmd VARCHAR(255);
       ...
    END
    @@
    DELIMITER ;