Mysql存储过程用于构造数据

在测试过程中,需要生成100000条库存数据,通过下单,收货,全流程走下来比较耗时,这里使用mysql存储过程,快速大批量生成库存数据,方便快速大批量验证。

代码示例如下图:

drop PROCEDURE inv_create;

delimiter  $$
create procedure inv_create(in n int)
begin
	DECLARE lotseq varchar(50);
	while n > 0 DO
		SET lotseq := CONCAT('RT-000000011',n);
		INSERT INTO inv_lot_attr (`lot_seq`, `rec_date`, `lot_attr01`, `lot_attr02`, `lot_attr03`, `lot_attr04`, `lot_attr05`, `lot_attr06`, `lot_attr07`, `lot_attr08`, `lot_attr09`, `lot_attr10`, `lot_attr11`, `lot_attr12`, `create_time`, `creator_code`, `creator_name`, `modify_time`, `modifier_code`, `modifier_name`) VALUES
		 (lotseq, NULL, 'lot_attr01', '', CONCAT('SAD',n), '04', 'SDF', '06', '07', '08', '12', '', '', '', '2023-05-09 11:10:24', '', '', '2023-05-09 19:55:09', '', '');

		INSERT INTO inv_inventory ( `warehouse_code`, `location_code`, `company_code`, `item_code`, `lot_seq`, `trace_num`, `lpn`, `rec_date`, `on_hand_qty`, `allocated_qty`, `available_qty`, `move_in_qty`, `move_out_qty`, `hold_qty`, `create_time`, `creator_code`, `creator_name`, `modify_time`, `modifier_code`, `modifier_name`) VALUES 
		( 'WH', 'TESTKW002', 'HZ', 'LWSP110053', lotseq, '*', '*', '2023-05-06', '5.00000', '0.00000', '0.00000', '0.00000', '0.00000', '0.00000', '2023-05-06 14:06:21', '', '', '2023-05-06 14:06:21', '', '');
		
		if n % 1000 = 0 THEN
			commit;
		end if;
		set n := n - 1;
	end while;
end $$
delimiter;



call inv_create(10000);


show procedure status like "inv_create";

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值