CREATE PROCEDURE updateTradePerformanceData()
BEGIN
declare stopFlag int;
declare parentOrgId varchar(100);
declare orgaid varchar(100);
DECLARE dataid varchar(100);
declare hasCount int;
-- 申明游标
declare tradePerformanceCuror cursor for
select
fid,fkorgaid
from t_trade_performance;
OPEN tradePerformanceCuror;
REPEAT
FETCH tradePerformanceCuror INTO dataid,orgaid;
BEGIN
select count(1) into hasCount from t_bd_org o where o.fid = orgaid;
if (orgaid is not null and hasCount > 0) then
select o.fkparentid into parentOrgId from t_bd_org o where o.fid = orgaid;
update t_trade_performance set fkorgbid = parentOrgId where fid = dataid;
-- 处理逻辑
end if;
commit;
END;
UNTIL stopFlag = 1
END REPEAT;
CLOSE tradePerformanceCuror;
END;
BEGIN
declare stopFlag int;
declare parentOrgId varchar(100);
declare orgaid varchar(100);
DECLARE dataid varchar(100);
declare hasCount int;
-- 申明游标
declare tradePerformanceCuror cursor for
select
fid,fkorgaid
from t_trade_performance;
-- 申明跳出循环
OPEN tradePerformanceCuror;
REPEAT
FETCH tradePerformanceCuror INTO dataid,orgaid;
BEGIN
select count(1) into hasCount from t_bd_org o where o.fid = orgaid;
if (orgaid is not null and hasCount > 0) then
select o.fkparentid into parentOrgId from t_bd_org o where o.fid = orgaid;
update t_trade_performance set fkorgbid = parentOrgId where fid = dataid;
-- 处理逻辑
end if;
commit;
END;
UNTIL stopFlag = 1
END REPEAT;
CLOSE tradePerformanceCuror;
END;
本文介绍了一个用于更新交易绩效数据存储过程的实现,包括声明变量、游标操作、循环处理以及数据库更新等关键步骤。
4万+

被折叠的 条评论
为什么被折叠?



