DROP PROCEDURE IF EXISTS excute_job_v340;

創(chuàng)新互聯(lián)公司于2013年創(chuàng)立,先為赤峰等服務(wù)建站,赤峰等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為赤峰企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
create procedure excute_job_v340()
begin?
declare rdevid int; //聲明參數(shù)
declare rech_id int;
declare slot int;
declare new_rech_id int;
declare new_price DOUBLE;//聲明參數(shù)
declare done INT DEFAULT FALSE;////聲明結(jié)束標(biāo)識(shí)參數(shù)
--? 聲明游標(biāo)
DECLARE rdevrech_id CURSOR FOR
select r.id as rdevid,r.rechargeconfig_id as rech_id,r.slot_no as slot from b_device_tbl dev
LEFT JOIN r_device_rechargeconfig_tbl r on dev.id= r.device_id
where dev.dev_typedef_id =7 and dev.masterid is not NULL? and r.rechargeconfig_type=4 and r.is_deleted=0 and ????????????????r.slot_no is not? NULL;
-- 將結(jié)束標(biāo)志綁定到游標(biāo)
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
-- 打開游標(biāo)
OPEN? rdevrech_id;? ?
-- 遍歷
read_loop: LOOP
-- 取值
FETCH? NEXT from rdevrech_id INTO rdevid,rech_id,slot;
IF done THEN
LEAVE read_loop;
END IF;// 結(jié)束判斷
select price into new_price from c_device_rechargeconfig_item_tbl where rechargeconfig_id =rech_id limit 1;
INSERT INTO `c_device_rechargeconfig_tbl` (? `type`, `style_id`, `is_default`, `dev_type_code`, `is_deleted`, ????????????????`create_time`, `slot_no`)
VALUES ( '4', NULL, '0', '0', '0', '2019-08-19 15:59:24',slot );
select max(id) into new_rech_id from c_device_rechargeconfig_tbl ;
INSERT INTO? `c_device_rechargeconfig_item_tbl` (? `price`, `goods`, `description`, `is_deleted`, `create_time`, ????????????????????????`rechargeconfig_id` )
VALUES (? new_price,new_price, '0.00', '0', '2019-08-19 15:59:24', new_rech_id);
update r_device_rechargeconfig_tbl set rechargeconfig_id=new_rech_id where id=rdevid;
END LOOP;
CLOSE rdevrech_id;
end;
call excute_job_v340() ;//調(diào)用執(zhí)行
已經(jīng)測試,創(chuàng)建并運(yùn)行下面的存儲(chǔ)過程可以循環(huán)添加數(shù)據(jù):
create procedure dowhile()
begin
declare i int default 0;
start transaction;
while i50 do
insert into users(userId,userName,userPwd) values(null,concat('s00',i),123456);
set i=i+1;
end while;
commit;
end;
delimiter;
一條insert語句批量插入多條記錄
常見的insert語句,向數(shù)據(jù)庫中,一條語句只能插入一條數(shù)據(jù):
insert into persons
(id_p, lastname , firstName, city )
values(204,'haha' , 'deng' , 'shenzhen');
(如上,僅插入了一條記錄)
怎樣一次insert插入多條記錄呢?
示例:
insert into persons
(id_p, lastname , firstName, city )
values
(200,'haha' , 'deng' , 'shenzhen'),
(201,'haha2' , 'deng' , 'GD'),
(202,'haha3' , 'deng' , 'Beijing');
這樣就批量插入數(shù)據(jù)了, 遵循這樣的語法,就可以批量插入數(shù)據(jù)了。
執(zhí)行成功
本文題目:mysql怎么循環(huán)插入 mysql 循環(huán)引用
本文鏈接:http://www.chinadenli.net/article48/hpijhp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供移動(dòng)網(wǎng)站建設(shè)、網(wǎng)站維護(hù)、服務(wù)器托管、App開發(fā)、電子商務(wù)、網(wǎng)站設(shè)計(jì)公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)