简体   繁体   中英

I try to create basic trigger but return error 1064

DELIMITER //
CREATE TRIGGER inserccionSocio AFTER INSERT ON socio FOR EACH ROW
BEGIN
    DECLARE anioInscripcion pago.anio%type;
    SELECT EXTRACT(YEAR from fechaInscripccion) INTO anioInscripcion FROM socio WHERE id = :NEW.id; 
    INSERT INTO pago VALUES(NEW.id,anioInscripcion);
END;
//

I'm trying this trigger but return #1064 error.

Something is wrong in your syntax near 'DECLARE anioInscripcion pago.anio%type; BEGIN SELECT EXTRACT(YEAR from...' in the second line.

I use 10.4.27-MariaDB.

I look around 'DECLARE anioInscripcion pago.anio%type; BEGIN SELECT EXTRACT(YEAR from...' en la linea 2 'DECLARE anioInscripcion pago.anio%type; BEGIN SELECT EXTRACT(YEAR from...' en la linea 2

but i cant find mistakes.

The problem is this: pago.anio%type; be equal to a integer

And the method EXTRACT is collect in VARCHAR or in DATE, what I have done is saving them in VARCHAR instead of saving them in integer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM