MySQL在存储过程中实现while循环

whlie 循环

drop  procedure if exists sample_while_loop;
delimiter //
create procedure sample_while_loop ()
begin
	declare counter int default 1;
	while counter<10 DO
		select counter;
	    set counter = counter +1;
	end while;
end //
call   sample_while_loop() //
drop  procedure sample_while_loop //
delimiter ;

工作实际使用

循环2500次在表中插入数据,插入的字段值中有rownum

drop procedure if exists testInsert;
DELIMITER $$
create procedure testInsert ()
begin
	declare rownum int default 1;

while rownum<2500 DO
     insert
	into
	vip_point_spec_rule(
	saas_cust_id,
	vip_point_spec_rule_id,
	vip_point_prj_id,
	grp_type,
	grp_code,
	grp_name,point_rate,crt_date,crt_usr_id,crt_usr_code,upd_date,upd_usr_id,upd_usr_code,org_group_id)
select
	'0',
	nc.cls_id ,
	'1454871602956075166',
	'C',
	nc.cls_code ,
	nc.cls_name, 
    rownum,
	sysdate() ,
	'1353007673544540190',
	'0023',
	date_format(sysdate(), '%Y-%m-%d'),
	'1353007673544540190',
	'0023',
	'0'
from
	nav_category nc limit rownum, 1;
	 set rownum = rownum +1;

	end while;
end$$
call testInsert() $$
drop procedure testInsert $$
DELIMITER ;

  • 8
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值