Mysql数据库中 ,涉及事物,循环添加数据
2 (
3 in subjects VARCHAR(200),
4 in detail text,
5 in useid int,
6 in isdelete int,
7 in confirm INT,
8 in time DateTime,
9 in acceptUserId VARCHAR(500),
10 in isread INT
11
12 )
13 BEGIN
14 declare cnt int default 0;
15 declare i int default 0;
16 declare growthid int DEFAULT 0;
17 DECLARE t_error INTEGER DEFAULT 0;
18 DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET t_error=1;
19 START TRANSACTION;
20
21 INSERT into wc_broadcast(id,`subject`,content,userId,isDelete,isConfirm,addDate)VALUES(subjects,detail,useid,isdelete,confirm,time);
22 select LAST_INSERT_ID() into growthid;
23 /*字符串切割后的总数*/
24 //&为分隔符
25 //func_get_split_string_tota 是函数
26 set cnt = func_get_split_string_total(acceptUserId,‘&‘);
27 WHILE i<cnt
28 DO
29 insert INTO wc_broadcastinfo(id,broadcastid,userid,isread)VALUES(growthid,func_get_split_string(acceptUserId,‘&‘,i),isread);
30 set i = i + 1;
31 end WHILE;
32
33 IF t_error = 0 THEN
34 commit;
35 ELSE
36 ROLLBACK;
37 END IF;
38
39 END
View Code
View Code
2.测设分割字符串
View Code
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。