1. 程式人生 > >儲存過程迴圈新增資料到資料庫中

儲存過程迴圈新增資料到資料庫中

CREATE DEFINER=`root`@`%` PROCEDURE `myproc`()
BEGIN
	DECLARE
		num INT ;
	SET num = 1 ;
	WHILE num < 25 DO
		INSERT INTO product (
	product_type_id,
	product_name,
	product_format,
	product_desc_price,
	product_price,	
	product_picture,
	business_id,
	product_status,
	queue
)
VALUES
	(	
		'1',
		'虎跑優質飲用水 19L',
		'19L*1/桶',
		'桶',
		'10.00',		
		'/picture/water/2017052009.png',
		num,
		'open',
		'6'
	);
INSERT INTO product (
	product_type_id,
	product_name,
	product_format,
	product_desc_price,
	product_price,	
	product_picture,
	business_id,
	product_status,
	queue
)
VALUES
	(	
		'1',
		'千島湖飲用水 19L',
		'19L*1/桶',
		'桶',
		'10.00',		
		'/picture/water/2017052010.png',
		num,
		'open',
		'7'
	);
	SET num = num + 1 ;
	END
	WHILE ;
	END