您好 这个TRIGGER语句中是否有任何错误。当我尝试在phpAdmin中运行它时,它会给出错误“#1064 - 您的SQL语法中有错误;请查看与您的MySQL服务器版本对应的手册,以获得正确的语法在“SELECT Count(*)into SIM_CCode_Count”附近使用。我不知道这有什么问题。请帮助我
这是我的触发陈述
CREATE TRIGGER Is_CountryCode_There After INSERT on mr_details FOR EACH ROW
BEGIN
DECLARE SIM_CCode_Count INTEGER;
DECLARE NET_CCode_Count INTEGER;
SELECT Count(*) into SIM_CCode_Count FROM Country_Main where CountryCode=NEW.SimCntISO;
IF SIM_CCode_Count=0 THEN
INSERT INTO Country_Main(CountryCode,CountryName) Values(NEW.SIMCntISO,"Unknown");
END IF
If NEW.SimCntISO<>NEW.NetCntISO then
SELECT Count(*) into NET_CCode_Count FROM Country_Main
where CountryCode=NEW.NetCntISO
IF NET_CCode_Count=0 THEN
INSERT INTO Country_Main(CountryCode,CountryName) Values(NEW.NETCntISO,"Unknown");
END IF
END IF
END
答案 0 :(得分:3)
如果没有正确解释您的要求和表格以及您希望触发器做什么,很难说出触发器中是否存在任何问题。 但据我所知,有一些小的修正需要做.. 试试此规范,并详细了解您的要求..
CREATE TRIGGER Is_CountryCode_There After INSERT on mr_details FOR EACH ROW
BEGIN
DECLARE SIM_CCode_Count INTEGER;
DECLARE NET_CCode_Count INTEGER;
SELECT Count(*) into SIM_CCode_Count FROM Country_Main where CountryCode=NEW.SimCntISO;
IF SIM_CCode_Count=0 THEN
INSERT INTO Country_Main(CountryCode,CountryName) Values(NEW.SIMCntISO,"Unknown");
END IF;
If (NEW.SimCntISO<>NEW.NetCntISO) then
SELECT Count(*) into NET_CCode_Count FROM Country_Main
where CountryCode=NEW.NetCntISO;
IF NET_CCode_Count=0 THEN
INSERT INTO Country_Main(CountryCode,CountryName) Values(NEW.NETCntISO,"Unknown");
END IF;
End IF;
END;
答案 1 :(得分:0)
您必须在触发器语句之前声明一个mysql语句分隔符:
DELIMITER |
CREATE TRIGGER ...
(your code)
END|
DELIMITER ;
否则MySQL会将此语句中的;
解释为语句提交并立即执行代码。将分隔符更改为其他字符后,您可以安全地在触发器声明中使用分号。
见这里:http://dev.mysql.com/doc/refman/5.0/en/create-procedure.html