MYSQL存储过程循环遍历插入数据

更新时间:2023-06-22 12:43:29 阅读: 评论:0

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

本文发布于:2023-06-22 12:43:29,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/153713.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:循环   记录   实现   控制
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图