I am trying to write the following trigger:
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 ;
The error is:
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
The tables are quite simple:
CREATE TABLE test(
s INT
);
CREATE TABLE testt(
m INT,
a INT,
sID INT,
t VARCHAR(200),
d VARCHAR(500)
);
Thanks.
You miss END IF; at the end:
IF c = 0 THEN INSERT INTO testt VALUES (m, a, sID, '', '');
END IF;
END $$
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.