遇到一mysql触发器的离奇现象,求解!

gesnpt 2008-09-27 05:16:07
我有一个叫product的表,为这个表建了一个触发器,触发器如下(略有改动):
DELIMITER $$

CREATE
TRIGGER `productTrigger` AFTER INSERT ON `product`
FOR EACH ROW BEGIN
declare bookingtime varchar(15);
declare firstcomma int(2);
declare secondcomma int(2);
declare tmp varchar(500);
declare newcontent varchar(500);
declare i int(2) DEFAULT 1;
declare tmpIndex int(2);
declare param varchar(50);
declare judge BOOLEAN DEFAULT true;
declare required0 varchar(10);
declare required1 varchar(10);
declare codebaseCount int(1) DEFAULT 0;
set newcontent = concat(new.content,'&');
set firstcomma = LOCATE(',', newcontent);
set secondcomma = LOCATE(',', newcontent, firstcomma+1);

if firstcomma > 0 and secondcomma >0 then
set bookingtime = SUBSTRING(newcontent, 1, firstcomma-1);
set tmp = SUBSTRING(newcontent, secondcomma+1);
while (i>1 or judge) do

set tmpIndex = LOCATE('&', tmp, i);
set param = SUBSTRING(tmp, i, tmpIndex-i);
if(LOCATE('required0=',param)>0) then
set required0 = SUBSTRING(param, LOCATE('=',param)+1);
elseif(LOCATE('required1=',param)>0) then
set required1 = SUBSTRING(param, LOCATE('=',param)+1);
end if;
set i = tmpIndex+1;
set judge = false;
end while;

if length(required0)>0 then
select count(*) into codebaseCount from test where `required0`=required0;
if codebaseCount = 1 then
insert into infonew (`required0`,`required1`,`TIMESTAMP`) values (required0,required1,bookingtime);
end if;
end if;
end if;
END;
$$

DELIMITER ;

只要是对字段进行一些字符串的拆分,然后将拆分内容插入到另外的一个表里。
现在的情况是,我一旦建立了这个trigger,product表的数据会被不停的重复插入,注意是product表,不是infonew这个表,而且是mysql自己在不停的插入,哪位神仙遇到过这种情况呀!
...全文
79 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
gesnpt 2008-10-26
  • 打赏
  • 举报
回复
现在看应该不是mysql的问题,貌似是log4j向mysql数据库插入数据的时候有bug

gesnpt 2008-09-28
  • 打赏
  • 举报
回复
现在看好像是每次向product表插一条数据,就会将之前插入的数据重新都再插一次,会在短时间内就插入product表几百万的数据,很夸张。
难道有一条数据插入失败会导致mysql重复插入吗?
WWWWA 2008-09-28
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 gesnpt 的回复:]
现在看好像是每次向product表插一条数据,就会将之前插入的数据重新都再插一次,会在短时间内就插入product表几百万的数据,很夸张。
难道有一条数据插入失败会导致mysql重复插入吗?
[/Quote]
应该不会,而且MYSQL触发器不能对同表进行操作,应该是触发了其它表的触发器吧
WWWWA 2008-09-28
  • 打赏
  • 举报
回复
没有遇到过此问题,infonew 是否有触发器,表间关系?
denniswwh 2008-09-27
  • 打赏
  • 举报
回复
mysql的bug?插入的数据都一样?

56,687

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧