mysql中調試觸發器的方法
具體調試方法如下:
CREATE DEFINER=`root`@`%` TRIGGER `t_afterinsert_to_summary` AFTER INSERT ON `a` FOR EACH ROWbegin
declare v1 VARCHAR( 20 );
declare v2 VARCHAR( 20 );
declare done int default 0;
DECLARE mob VARCHAR ( 20 );
DECLARE content VARCHAR ( 500 );
DECLARE node_ip VARCHAR ( 20 );
DECLARE mobile_list CURSOR FOR SELECT mobile FROM c WHERE c.c = new.c1;
declare continue handler for not FOUND set done = 1; /*done = true;亦可*/
insert into t (x,cc) VALUES( new.c1, 'topfirest0');-------人為插入作業點
IF ( new.c1 = 0 ) THEN
insert into t (x,cc) VALUES( new.c1, 'firest1');-------人為插入作業點
select b into v1 from b where b.a=new.c1;
set v2=new.c1;
insert into t (x,cc) VALUES( new.c1, 'firest2');-------人為插入作業點
SET content = CONCAT( 'abcabcabc', '[', v2, ']', 'dede', v2,'ccddddd' );
insert into t (x,cc) VALUES( new.c1, 'firest3');-------人為插入作業點
insert into t (x,cc) VALUES( new.c1, 'firest4');-------人為插入作業點
OPEN mobile_list;-- 將游標中的值賦值給變量,要注意sql結果列的順序
REPEAT
FETCH mobile_list INTO mob;-- while循環
if not done then
insert into t (x,cc) VALUES( new.c1, 'firest5');-------人為插入作業點
INSERT INTO t (x,cc) VALUES( v2, content);
end if;
-- 關閉游標
until done end repeat;
CLOSE mobile_list;
END IF;
end;