phpAdmin 中的 MySQL 触发器错误
你好 此 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
Hi
Is there any error in this TRIGGER Statement.When ever i try to run this in phpAdmin its giving error saying "#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 "SELECT Count(*) into SIM_CCode_Count".I cant get what's wrong in this..please help me
This is my trigger statement
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果没有对您的要求、表格以及您期望此触发器执行的操作进行适当的解释,则很难说触发器中是否存在任何问题。
但据我所知,需要进行一些小的修正。
尝试此代码并详细了解您的要求。
Without proper explanation about your requirement and about tables and what you are expecting this trigger to do,its very difficult to say if any issues there in your trigger..
But as far as i can see there is some minor correction need to be done..
Try this Code and let know in detail your requirements..
你必须在触发器语句之前声明一个 mysql 语句分隔符:
否则 MySQL 会将此语句中的
;
解释为语句提交并立即执行代码。将分隔符更改为不同的字符后,您可以安全地在触发器声明中使用分号。请参阅此处: http://dev.mysql.com/doc/ refman/5.0/en/create-procedure.html
You have to declare a mysql-statement delimiter before the trigger statement:
Otherwise MySQL interprets your
;
in this statement as statement commit and executes the code immidiately. With the delimiter changed to a different character you can use the semicolon inside the trigger declaration safely.See here: http://dev.mysql.com/doc/refman/5.0/en/create-procedure.html