oracle for游标 会丢失数据处理
答案:2 悬赏:30 手机版
解决时间 2021-12-28 08:04
- 提问者网友:像風在裏
- 2021-12-27 20:51
oracle for游标 会丢失数据处理
最佳答案
- 五星知识达人网友:想偏头吻你
- 2021-12-27 21:55
(游标的性能一般不好):创建一个临时表:
[sql]
declare @tempTable table(ID int identity(1,1), unitID int, unitState int, partID bigint)
insert into @tempTable
select distinct u.id, u.UnitStateID, u.PartID
from ffUnit u
join ffUnitDetail ud on u.id = ud.unitID
where ud.InmostPackageID = @packageID
declare @i int
declare @j int
set @i = 0
select @j = MAX(ID) from @tempTable
begin tran---Rex
while @i < @j begin
set @i = @i+1
set @UnitID = null
set @CurrUnitStateID = null
set @PartID = null
select @UnitID=unitID, @CurrUnitStateID = unitState, @PartID = partID from @tempTable where ID = @i
exec @ret = objUNTCheckRouting @UnitID, @xmlPart, @xmlStation
if @ret <> 0 or @@ERROR >0
begin
if @@TRANCOUNT = 1 rollback else commit
return @ret
end
end
commit tran
[sql]
declare @tempTable table(ID int identity(1,1), unitID int, unitState int, partID bigint)
insert into @tempTable
select distinct u.id, u.UnitStateID, u.PartID
from ffUnit u
join ffUnitDetail ud on u.id = ud.unitID
where ud.InmostPackageID = @packageID
declare @i int
declare @j int
set @i = 0
select @j = MAX(ID) from @tempTable
begin tran---Rex
while @i < @j begin
set @i = @i+1
set @UnitID = null
set @CurrUnitStateID = null
set @PartID = null
select @UnitID=unitID, @CurrUnitStateID = unitState, @PartID = partID from @tempTable where ID = @i
exec @ret = objUNTCheckRouting @UnitID, @xmlPart, @xmlStation
if @ret <> 0 or @@ERROR >0
begin
if @@TRANCOUNT = 1 rollback else commit
return @ret
end
end
commit tran
全部回答
- 1楼网友:孤老序
- 2021-12-27 22:12
游标比较慢,游标返回的记录条数越多,性能越低,使用游标适用于记录较少的记录集的处理。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯