Syntax error and I do not know where

2

I'm wanting to create a discount trigger for if the user selects the payment method 6 that is billet he has 15% discount in the amount that will be paid, then the ValuePagar q is where the value that the person will get is to receive the discounted value

CREATE TRIGGER Desconto BEFORE INSERT
ON Pagamento
FOR EACH ROW 
BEGIN
    IF NEW.CodigoFormaPagamento = 6 THEN
        SET NEW.ValorPagar = (NEW.ValorPagar * 0.15);
    END IF;
END;
    
asked by anonymous 09.06.2018 / 22:15

1 answer

3

By default MySQL understands ; as an instruction delimiter, so you should set a temporary delimiter other than ; , otherwise it will not know where the procedures and instructions end in code.

DELIMITER $$ /* $$ como delimitador temporário  */
CREATE TRIGGER Desconto BEFORE INSERT
ON Pagamento
FOR EACH ROW
BEGIN
    IF NEW.CodigoFormaPagamento = 6 THEN
        SET NEW.ValorPagar = (NEW.ValorPagar * 0.15);
    END IF
END $$
DELIMITER ; /* restaura o delimitador original  */

Source on the official documentation page

    
09.06.2018 / 23:05