2016-03-31 17 views
0
DELIMITER // 
CREATE TRIGGER `enclosure-after_update-time` AFTER UPDATE ON `enclosure` 
FOR EACH ROW BEGIN 
    IF NEW.time <> OLD.time THEN 
     DECLARE done INT DEFAULT FALSE; 
     DECLARE ids INT; 
     DECLARE invoice_ids INT; 
     DECLARE cur CURSOR FOR SELECT id AS ids, invoice_id AS invoice_ids FROM accounting WHERE enclosure_id = NEW.id; 
     DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; 

     OPEN cur; 
      ins_loop: LOOP 
       FETCH cur INTO ids, invoice_ids; 
       IF done THEN 
        LEAVE ins_loop; 
       END IF; 
       UPDATE accounting SET time=NEW.time WHERE id=ids; 
       IF invoice_ids THEN 
        UPDATE invoice SET time=NEW.time WHERE id=invoice_ids; 
       END IF; 
      END LOOP; 
     CLOSE cur; 
    END IF; 
END 
// 
DELIMITER ; 

hata

#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 'DECLARE done INT DEFAULT FALSE; 
     DECLARE ids INT; 
     DECLARE invoi' at line 4 
+0

'eğer daha önce (çok başında değişkenleri bildirme deneyin başlayan ') –

cevap

0

adresinden değişkenleri bildir çok

DELIMITER // 
CREATE TRIGGER `enclosure-after_update-time` AFTER UPDATE ON `enclosure` 
FOR EACH ROW BEGIN 
    DECLARE done INT DEFAULT FALSE; 
    DECLARE ids INT; 
    DECLARE invoice_ids INT; 
    DECLARE cur CURSOR FOR SELECT id, invoice_id INTO ids, invoice_ids FROM accounting WHERE enclosure_id = NEW.id; 
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; 

    IF NEW.time <> OLD.time THEN 
     OPEN cur; 
      ins_loop: LOOP 
       FETCH cur INTO ids, invoice_ids; 
       IF done THEN 
        LEAVE ins_loop; 
       END IF; 
       UPDATE accounting SET time=NEW.time WHERE id=ids; 
       IF invoice_ids THEN 
        UPDATE invoice SET time=NEW.time WHERE id=invoice_ids; 
       END IF; 
      END LOOP; 
     CLOSE cur; 
    END IF; 
END 
// 
DELIMITER ; 
+0

sonra # 1323 - İmleç SEÇİMİ INTO' – clarkk

+0

olmamalıdır. SELECT ... INTO ... değiştirildikten sonra "SELECT sütun AS alias" ile çalışır – clarkk

İlgili konular