DELIMITER //
CREATE PROCEDURE proc_tmp()
BEGIN
DECLARE done INT DEFAULT 0;
DECLARE product_Id VARCHAR(255);
DECLARE yuanliao VARCHAR(255);
DECLARE miaoshu VARCHAR(255);
DECLARE shazhi VARCHAR(255);
DECLARE midu VARCHAR(255);
DECLARE mf VARCHAR(255);
DECLARE zuzhi VARCHAR(255);
DECLARE quality VARCHAR(255);
DECLARE shuliang VARCHAR(255);
DECLARE jiage VARCHAR(255);
DECLARE price_date VARCHAR(255);
DECLARE idCur CURSOR FOR SELECT productId,yl,ylms,sz,md,fk,zz,qa,amount,price,pricedate FROM sheet1;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
OPEN idCur;
REPEAT
FETCH idCur INTO product_Id,yuanliao,miaoshu,shazhi,midu,mf,zuzhi,quality,shuliang,jiage,price_date;
IF NOT done THEN
INSERT INTO static_data(model_id,dataKey,dataVal,product_id) VALUES(3,'yl',yuanliao,product_Id);
INSERT INTO static_data(model_id,dataKey,dataVal,product_id) VALUES(3,'ylms',miaoshu,product_Id);
INSERT INTO static_data(model_id,dataKey,dataVal,product_id) VALUES(3,'sz',shazhi,product_Id);
INSERT INTO static_data(model_id,dataKey,dataVal,product_id) VALUES(3,'md',midu,product_Id);
INSERT INTO static_data(model_id,dataKey,dataVal,product_id) VALUES(3,'fk',mf,product_Id);
INSERT INTO static_data(model_id,dataKey,dataVal,product_id) VALUES(3,'zz',zuzhi,product_Id);
INSERT INTO static_data(model_id,dataKey,dataVal,product_id) VALUES(3,'qa',quality,product_Id);
INSERT INTO static_data(model_id,dataKey,dataVal,product_id) VALUES(3,'amount',shuliang,product_Id);
INSERT INTO static_data(model_id,dataKey,dataVal,product_id) VALUES(3,'price',jiage,product_Id);
INSERT INTO static_data(model_id,dataKey,dataVal,product_id) VALUES(3,'pricedate',price_date,product_Id);
END IF;
UNTIL done END REPEAT;
CLOSE idCur;
END//
DELIMITER ;
CALL proc_tmp();
DROP PROCEDURE proc_tmp;
DELETE FROM sheet1;
定义的变量不能和select里的同名