Declare variables in a Trigger in mysql

Asked

Viewed 264 times

0

I am creating a Trigger in mysql with use of variables and this returning me an error and as I am starting to use mysql now I could not solve the problem, follows the error:

Executing:
DROP TRIGGER IF EXISTS `silimed_new`.`pedido_BEFORE_INSERT_tem_fat`;

DELIMITER $$
USE `silimed_new`$$
CREATE DEFINER = CURRENT_USER TRIGGER `silimed_new`.`pedido_BEFORE_INSERT_tem_fat` BEFORE INSERT ON `pedido` FOR EACH ROW FOLLOWS `pedido_BEFORE_INSERT`
$$
DELIMITER ;
DROP TRIGGER IF EXISTS `silimed_new`.`pedido_BEFORE_INSERT_1`;

DELIMITER $$
USE `silimed_new`$$
CREATE DEFINER = CURRENT_USER TRIGGER `silimed_new`.`pedido_BEFORE_INSERT_1` BEFORE INSERT ON `pedido` FOR EACH ROW
BEGIN
    declare V_consultor_nome VARCHAR(255);
    declare V_dest_nf VARCHAR(255);

    select medico.consultor_nome,medico.dest_nf
    from pedido
    inner join medico
    where pedido.id = (select * from (select max(id) from pedido) as dt );
    
    SET NEW.consultor = V_consultor_nome;
    SET NEW.dest_nf = V_dest_nf;
END$$
DELIMITER ;

Operation failed: There was an error while applying the SQL script to the database.
ERROR 1064: 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 '' at line 1
SQL Statement:
CREATE DEFINER = CURRENT_USER TRIGGER `silimed_new`.`pedido_BEFORE_INSERT_tem_fat` BEFORE INSERT ON `pedido` FOR EACH ROW FOLLOWS `pedido_BEFORE_INSERT`
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.