2014-01-13 103 views
0

我想寫以下觸發語法錯誤:MySQL的 - 上觸發

DELIMITER $$ 

CREATE TRIGGER trigger_test_1 AFTER INSERT ON test FOR EACH ROW 
    BEGIN 
     DECLARE sID INT; 
     DECLARE m INT; 
     DECLARE a INT; 
     DECLARE c INT; 

     SET sID = NEW.s; 
     SELECT MONTH(NOW()) INTO m; 
     SELECT YEAR(NOW()) INTO a; 

     SELECT COUNT(*) INTO c 
      FROM testt t 
      WHERE t.m = m AND t.a = a AND t.sID = sID; 

     IF c = 0 THEN 
      INSERT INTO testt VALUES (m, a, sID, '', ''); 
     END $$ 

DELIMITER ; 

的錯誤是:

ERROR 1064 (42000): 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 15 

的表是很簡單的:

CREATE TABLE test(
    s INT 
); 

CREATE TABLE testt(
    m INT, 
    a INT, 
    sID INT, 
    t VARCHAR(200), 
    d VARCHAR(500) 
); 

謝謝。

回答

2

你錯過END IF;在最後:

IF c = 0 THEN INSERT INTO testt VALUES (m, a, sID, '', ''); 
END IF; 
END $$ 
+0

謝謝,我擔心其他方面,錯過了這個小小的錯誤。 – Minoru

+0

從問題開始之前必須等待一段時間才能接受任何問題。我會盡快做到。 – Minoru