Mysql循環insert數據


開發自測時,數據庫需要造大量數據時,要用到Mysql存儲過程相關知識,下面分享下,希望對小伙伴們有所幫助:

CREATE PROCEDURE test() #創建存儲函數;
BEGIN
DECLARE i INT DEFAULT 1;

WHILE i < 5000 DO

#下面的insert語法要改成自己的表,同時構造value.id,要考慮防重;
INSERT INTO `wbms_1`.`waybill_weight_volume_2`(`id`, `tenant_id`, `waybill_code`, `operate_code`, `volume`, `weight`, `length`, `width`, `height`, `weight_time`, `volume_time`, `ope_type`, `operator_code`, `operator_name`, `operate_station_code`, `operate_station`, `is_delete`, `create_time`, `update_time`, `create_user`, `update_user`, `ts`) VALUES (1356063857646284800+i, 'test', 'ZY1000502218621', 'ZY1000502218621-1-2-', 55.0000, 55.0000, 5.5000, 55.0000, 55.0000, '2020-09-20 16:39:56', '2020-09-20 16:39:56', 3, '21180252', '陳青山', '308766', '南京江駿營業部', 0, '2021-02-01 10:16:32', '2021-02-01 10:16:32', NULL, NULL, '2021-02-01 10:16:32.000');
SET i = i+1;
end WHILE;

END;
CALL test();#調用存儲函數


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM