3

this is my trigger

CREATE TRIGGER proximo_pago 
AFTER INSERT ON pago FOR EACH ROW
BEGIN
    DECLARE max_orden integer;
    DECLARE num_lote =NEW.lote;
        BEGIN
            SET max_orden = (SELECT MAX(orden) FROM PAGO WHERE LOTE=num_lote);
            SELECT max_orden INTO : NEW.orden from dual;
            END
END

and the error

Error SQL query:

CREATE TRIGGER proximo_pago 
AFTER INSERT ON pago FOR EACH ROW
BEGIN
    DECLARE max_orden integer;

MySQL said: Documentation

#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 4

2
  • 1
    did you change the delimeter? if not, then the ; on your first declare is terminating the entire trigger definition. Commented May 29, 2015 at 15:52
  • You need to change the delimiter before defining the trigger. Try delimiter / and put that character also at the end of your trigger definition. Commented May 29, 2015 at 15:52

1 Answer 1

4
 DECLARE TEMPKODE VARCHAR(10);
 DECLARE TEMP VARCHAR(5);

or if you want to assign you can use

 DECLARE TEMP INT DEFAULT 6;

To assign a variable

myvariable := TEMPKODE;
SET myvariable := TEMPKODE;

Maybe what you mean is :

CREATE TRIGGER proximo_pago 
AFTER INSERT ON pago FOR EACH ROW
BEGIN
DECLARE max_orden INT;
DECLARE num_lote INT;
    BEGIN
        SET num_lote := NEW.lote;
        SELECT MAX(ordern) INTO max_ordern FROM PAGO WHERE LOTE = num_lote;
        SET NEW.ordern := max_ordern;

END
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.