創建存儲過程循環插入數據


代碼如下

-- 如果存在testtt_insert同名的存儲過程,刪除
DROP PROCEDURE
IF EXISTS testtt_insert;

DELIMITER ;;
-- 創建一個存儲過程
CREATE PROCEDURE testtt_insert ()
BEGIN
-- 定義一個i,默認為1
DECLARE
i INT DEFAULT 1 ;
-- 如果i小於101
WHILE i < 101 DO
-- 執行以下語句
INSERT INTO `member_info` (
`id`,
`customer_name`,
`customer_sex`,
`customer_age`,
`customer_phone`,
`consumer_amount`,
`customer_integral`,
`customer_experience`,
`customer_service_name`,
`member_level`,
`customer_type`,
`application_name`,
`application_id`,
`province_code`,
`province_name`,
`city_code`,
`city_name`,
`region_code`,
`region_name`,
`detailed_address`,
`status`,
`created_by`,
`created_time`,
`updated_by`,
`updated_time`
)
VALUES
(
0,
-- 字符串后加1
CONCAT('曹操', i),
'1',
18,
-- 數字加1
18826473909+i,
200.00,
10,
10,
'',
'A級',
'復購',
'XXX小程序',
18,
'天津市',
'天津市',
'天津市',
'天津市',
'河北區',
'河北區',
'上課的空間',
'A',
1,
'2021-03-26 14:35:19',
1,
'2021-03-26 14:35:19'
) ;
-- 給已定義的變量i賦值
SET i = i + 1 ;
END-- 結束while循環
WHILE ; COMMIT ;-- commit提交事務
END;;-- 結束

CALL testtt_insert () ;-- 調用存儲過程

 


免責聲明!

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



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