问题描述
嗨,团队,
你能请你在下面的情况下吃点东西,并提出更好的替代方案吗?
我有暂存表-Tb_Staging_0001
列-卡 _ 否,地址 _ 1,..地址 _ 5,信用 _ 金额,借方 _ 金额,……等等 ..
和应用程序表 (tb_card_details) 具有与暂存表完全相同的列。
将数据从暂存移动到应用程序表的日常作业。
当前逻辑-
对于Tb_Staging_0001中的每一行,
对于 (从Tb_Staging_0001中选择 *)
循环
它将所有列与应用程序表进行比较。
喜欢
如果Tb_Staging_0001.Address_1!= tb_card_details.Address_1
然后
将其标记为已修改
如果结束;
如果Tb_Staging_0001.Address_2!= tb_card_details.Address_2
然后
将其标记为已修改
如果结束;
..
等等
并将这些列标记为出于审计目的而修改。
结束循环;
Problem here is staging tables contains around millions of records, and in loop it becomes time comsuming (IF 然后 for each loop)
您能否提出更好的方法,以便我尝试一下。
你能请你在下面的情况下吃点东西,并提出更好的替代方案吗?
我有暂存表-Tb_Staging_0001
列-卡 _ 否,地址 _ 1,..地址 _ 5,信用 _ 金额,借方 _ 金额,……等等 ..
和应用程序表 (tb_card_details) 具有与暂存表完全相同的列。
将数据从暂存移动到应用程序表的日常作业。
当前逻辑-
对于Tb_Staging_0001中的每一行,
对于 (从Tb_Staging_0001中选择 *)
循环
它将所有列与应用程序表进行比较。
喜欢
如果Tb_Staging_0001.Address_1!= tb_card_details.Address_1
然后
将其标记为已修改
如果结束;
如果Tb_Staging_0001.Address_2!= tb_card_details.Address_2
然后
将其标记为已修改
如果结束;
..
等等
并将这些列标记为出于审计目的而修改。
结束循环;
Problem here is staging tables contains around millions of records, and in loop it becomes time comsuming (IF 然后 for each loop)
您能否提出更好的方法,以便我尝试一下。
专家解答
合并应该可以解决问题,使用解码作为比较值的简单方法
merge into STAGING s
using ( select * from APP_TABLE ) a
on ( s.PK_COL1 = a.PK_COL1
and s.PK_COL2 = a.PK_COL2 -- ie, primary key columns
and ...
)
when matched then
update set
s.MODIFIED = 'YES'
where decode(s.COL1,a.COL1,1,0) = 0
or decode(s.COL2,a.COL2,1,0) = 0
or decode(s.COL3,a.COL3,1,0) = 0
or decode(s.COL4,a.COL4,1,0) = 0
or decode(s.COL5,a.COL5,1,0) = 0
...
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




