首页 > 代码库 > Mysql数据库中 ,涉及事物,循环添加数据
Mysql数据库中 ,涉及事物,循环添加数据
1 create PROCEDURE Usp_AddBoradCast
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
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
Mysql数据库中 ,涉及事物,循环添加数据
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。