MYSQL存储过程循环遍历插⼊数据melody意思
本⽰例通过 d while 循环控制游标来实现插⼊表记录。
DROP PROCEDURE IF exists pro_initCategoryForTradingEntity;
create procedure pro_initCategoryForTradingEntity(tradingEntityId int)
begin
declare f_parent,entityId int;
declare b int default 0; /*是否达到记录的末尾控制变量*/
3166什么意思declare f_name varchar(100);
DECLARE cur_1 CURSOR FOR lect FName,FParent,tradingEntityId from t_category_tag;
波兰语言
DECLARE CONTINUE HANDLER FOR NOT FOUND SET b = 1;
jerichoOPEN cur_1;
FETCH cur_1 INTO f_name, f_parent, entityId; /*获取第⼀条记录*/
while b<>1 do
inrt into t_category(FName,FParent,FTradingEntity) values(f_name, f_parent, entityId);
FETCH cur_1 INTO f_name, f_parent, entityId; /*取下⼀条记录*/indeed是什么意思
end while;
clo cur_1;
end;
call pro_initCategoryForTradingEntity(2);
本实例通过 d repeat 来循环控制。
CREATE DEFINER=`root`@`localhost` PROCEDURE `smt_update_goods_price`()
美国队长 彩蛋BEGIN
/
*局部变量的定义 declare*/
DECLARE goodsName varchar(50);
DECLARE goodsCode varchar(50);
DECLARE avgPrice varchar(50);
DECLARE maxPrice varchar(50);
DECLARE minPrice varchar(50);
DECLARE Done INT DEFAULT 0;
DECLARE rs cursor for(
lect goods_name, goods_code, avg(goods_price), max(goods_price), min(goods_price) from smt_temp_goods group by goods_code );
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET Done = 1;
clear是什么意思OPEN rs;痕迹英文
达蒙 塞尔瓦托FETCH NEXT FROM rs INTO goodsName, goodsCode, avgPrice, maxPrice, minPrice;
REPEAT
IF NOT Done THEN
inrt into smt_goods_price(id,goods_name,goods_code,avg_price,max_price,min_price) values(REPLACE(UUID(), '-',
''),goodsName,goodsCode,avgPrice,maxPrice,minPrice);
END IF;
FETCH NEXT FROM rs INTO goodsName, goodsCode, avgPrice, maxPrice, minPrice;
UNTIL Done END REPEAT;sonia
CLOSE rs;
END