Mysql資料庫中 ,涉及事物,迴圈添加資料

來源:互聯網
上載者:User

標籤:style   blog   http   color   os   io   ar   for   資料   

 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 ENDView Code1、具體函數

 View Code

View Code

 

2.測設分割字串

View Code 

 

Mysql資料庫中 ,涉及事物,迴圈添加資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.