RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
mysql怎么循环插入,mysql如何使用循环

利用mysql存储过程循环插入新数据并更新

DROP PROCEDURE IF EXISTS excute_job_v340;

成都创新互联-专业网站定制、快速模板网站建设、高性价比玉泉街道网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式玉泉街道网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖玉泉街道地区。费用合理售后完善,十余年实体公司更值得信赖。

create procedure excute_job_v340()

begin 

declare rdevid int; //声明参数

declare rech_id int;

declare slot int;

declare new_rech_id int;

declare new_price DOUBLE;//声明参数

declare done INT DEFAULT FALSE;////声明结束标识参数

--  声明游标

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;

-- 将结束标志绑定到游标

DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

-- 打开游标

OPEN  rdevrech_id;   

-- 遍历

read_loop: LOOP

-- 取值

FETCH  NEXT from rdevrech_id INTO rdevid,rech_id,slot;

IF done THEN

LEAVE read_loop;

END IF;// 结束判断

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() ;//调用执行

mysql 循环插入增量数据

CREATE DEFINER= XXXXXX @ % PROCEDURE PRO_taxpayer_invoice_statistical ()

BEGIN

DECLARE v_unifiedcredit_code VARCHAR(64);

DECLARE v_max_date datetime;

SELECT MAX(sii.created_on) INTO v_max_date

FROM sj_taxpayer_invoice_statistical_info sii;

SELECT 1;

END

mysql怎么for循环插入数据

把sql语句写到for循环的循环体里就好了,for不是mysql的语言,你还需要web语言来驱动(如php,jsp等)

mysql循环添加数据

已经测试,创建并运行下面的存储过程可以循环添加数据:

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;

mysql 怎么循环插入多条数据

一条insert语句批量插入多条记录

常见的insert语句,向数据库中,一条语句只能插入一条数据:

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');

这样就批量插入数据了, 遵循这样的语法,就可以批量插入数据了。

执行成功


当前文章:mysql怎么循环插入,mysql如何使用循环
网站网址:http://scyingshan.cn/article/hchcjh.html