mysql存儲過程批量造測試數據

delimiter $$ --結束符爲 $$
DROP PROCEDURE IF EXISTS mytest; --判斷進程是否存在,存在則刪除
CREATE PROCEDURE mytest()  --新建進程
BEGIN
declare i bigint(20) DEFAULT 1837;  
DECLARE ti bigint(20) DEFAULT 128693;
DECLARE tn bigint(20) DEFAULT 2019060408769;
declare file_id bigint(20) DEFAULT 117577;
DECLARE tin varchar(50);
DECLARE vin varchar(50);
  while i < 1937 do  --循環體
    SET tin=CONCAT('ws',tn);
    SET vin=CONCAT('TWYX',tn); --拼接字符串
    INSERT INTO ft_tax_finish_ticket(`id`, `ticket_id`, `ticket_no`, `receive_institution_id`, `status`,`vin`,`business_type`,`business_property`,`city_code`,`city_name`,`plate_number_owner`,`plate_number_owner_code`,`plate_number_owner_org_code`,`model`,`model_name`,`customer_name`,`customer_mobile`)  VALUES(i,ti,tin,'00001001',300,vin,1,1,'03205','自治區直轄縣級行政區劃五家渠市','浙江XXX有限公司台州分公司','000000','91441300MA4WFEG88G','202865','2018款 速騰 1.6L 自動舒適型','wyx','1237283');
    INSERT INTO ft_file_info(`id`,`data_id`,`file_type`,`file_sub_type`,`file_name`,`file_url`,`file_size`,`file_desc`,`ocr_result`,`is_valid`,`date_create`,`date_update`) VALUES(file_id,i,17,525,NULL,'https://img.XXX.com/76BD84A5-8139-47DF-A1CC-902B9352843A.jpg',NULL,NULL,NULL,1,'2019-06-01 16:23:47','2019-06-01 16:23:47');
    INSERT INTO ft_file_info(`id`,`data_id`,`file_type`,`file_sub_type`,`file_name`,`file_url`,`file_size`,`file_desc`,`ocr_result`,`is_valid`,`date_create`,`date_update`) VALUES(file_id+1,i,17,520,NULL,'https://img.XXX.com/1122FE18-9A00-4D44-A11C-06C1EC1D8668.jpg',NULL,NULL,NULL,1,'2019-06-01 16:23:47','2019-06-01 16:23:47');
    INSERT INTO ft_file_info(`id`,`data_id`,`file_type`,`file_sub_type`,`file_name`,`file_url`,`file_size`,`file_desc`,`ocr_result`,`is_valid`,`date_create`,`date_update`) VALUES(file_id+2,i,17,540,NULL,'https://img.XXX.com/C607C5D8-D9E1-4A21-9330-F011E8DAD991.jpg',NULL,NULL,NULL,1,'2019-06-01 16:23:47','2019-06-01 16:23:47');
    set i=i+1;
    set ti=ti+1;
    set tn=tn+1;
    set file_id=file_id+3;
  end while;
end $$ --結束定義語句
delimiter ; --先把結束符恢復爲 ;
call mytest(); --調用進程

適用範圍:插入表的數量及表之間的關聯較少

運行方法:直接在navicat上運行或者mysql執行環境運行,推薦navicat,編輯方便

注意:如果執行時報錯,把所有縮進去掉改成空格縮進,注意中英文標點

參考文章:https://www.cnblogs.com/veitch-623/p/6637619.html

語法和實例:https://www.cnblogs.com/cxxjohnson/p/5965194.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章