Syntax error and I don’t know where

Asked

Viewed 31 times

2

inserir a descrição da imagem aqui I want to create a discount Trigger for case the user select the form of payment 6 that is billet he has 15% discount on the amount q will be paid, then the Valorpagar q is where is the amount that the person will pick up 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;
  • I put the image to see where the error is happening

  • Obg for putting the code so it’s easy to copy.

  • How strange, here it is like this

  • I took it, now he is not accusing error in the last END but is accusing the other two where were already

  • using what you passed me worked out, but could you please explain to me?

1 answer

3


By default Mysql understands the ; as an instruction delimiter, so you must define a temporary delimiter other than ;, otherwise he won’t be able to know where the procedures and instructions in the code end.

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

Browser other questions tagged

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