代码贴出
一对一 t_warehouse_order.order_code -->t_warehouse_waybill.order_code 使用游标遍历单字段数据,每2000条一次事务。
点击(此处)折叠或打开
-
delimiter //
-
DROP PROCEDURE IF EXISTS insert_waybill;
-
CREATE PROCEDURE insert_waybill ()
-
BEGIN
-
DECLARE fig INT DEFAULT 0;
-
DECLARE var INT DEFAULT 0;
-
DECLARE code varchar(10);
-
DECLARE sw int default 0;
-
DECLARE yb01 cursor FOR select order_code from t_warehouse_order;
-
DECLARE CONTINUE HANDLER FOR NOT FOUND SET fig=1;
-
open yb01;
-
start transaction;
-
loop_lable01:LOOP
-
FETCH yb01 INTO code;
-
if fig=1 then
-
LEAVE loop_lable01;
-
end if;
- INSERT INTO t_warehouse_waybill ( id,order_code) VALUES ( var,code);
-
set sw=sw+1;
-
set var=var+1;
-
if (sw%2000=0) then
-
commit;
-
start transaction;
-
end if;
-
end LOOP loop_lable01;
-
commit;
-
close yb01;
-
-
END
-
//
- delimiter ;
点击(此处)折叠或打开
-
delimiter //
-
DROP PROCEDURE IF EXISTS packwaybill;
-
CREATE PROCEDURE packwaybill ()
-
BEGIN
-
DECLARE kig INT DEFAULT 0;
-
DECLARE wano varchar(20);
-
DECLARE pkno varchar(20);
-
DECLARE k INT DEFAULT 0;
-
DECLARE sw int default 0;
-
DECLARE wa01 cursor FOR select waybill_no from t_warehouse_waybill;
-
DECLARE pk01 cursor FOR select package_no from t_warehouse_package;
-
DECLARE CONTINUE HANDLER FOR NOT FOUND SET kig=1;
-
open pk01;
-
open wa01;
-
start transaction;
-
loop_lable01:LOOP
-
FETCH pk01 INTO pkno;
-
if kig=1 then
-
LEAVE loop_lable01;
-
end if;
-
set k=0 ;
-
while k<40 do
-
fetch wa01 into wano;
-
INSERT INTO t_warehouse_package_relation_waybill (package_no,way_bill_no)
-
values ( pkno,wano);
-
set sw=sw+1;
-
set k=k+1;
-
end while;
-
if (sw%2000=0) then
-
commit;
-
start transaction;
-
end if;
-
end LOOP loop_lable01;
-
commit;
-
close wa01;
-
close pk01;
-
-
END
-
//
- delimiter ;