a表只有126条记录,b表有140万记录
1.
这样写竟然需要3秒多才能update完,a.card_no,b.card_no必须是主键,不然会报错:ora-01779:cannot modify a colum which maps to non key-preserved table
2.
因为a表card_no不是主键了,所以改成这么写,第一次执行要了0.39秒,后面执行在0.016-0.03秒之间。
第二种写法应该是 in 这个where条件起了很大的作用。
1.
/*card_no必须是主键*/
Update ( Select (Case a.status When '挂失' Then '004' When '卡找回' Then '000'
When '取消用卡资格' Then '008' When '已还款' Then '000' End) status_new,
b.card_status,
(Case When a.status='取消用卡资格' Then 1 Else 0 End) increment_times,
b.suspend_times
From etl_daily_cardstatus a,etl_custcard b
Where a.card_no=b.card_no)
Set card_status=status_new,suspend_times=nvl(suspend_times,0)+increment_times;
这样写竟然需要3秒多才能update完,a.card_no,b.card_no必须是主键,不然会报错:ora-01779:cannot modify a colum which maps to non key-preserved table
2.
Update etl_custcard b
Set (b.card_status,b.suspend_times)=
(
Select (Case a.status When '挂失' Then '004' When '卡找回' Then '000'
When '取消用卡资格' Then '008' When '已还款' Then '000' End) status_new,
(Case When a.status='取消用卡资格' Then 1 Else 0 End) increment_times
From
(Select * From (Select card_no,status,
dense_rank() over (partition by card_no order by seqno desc) seq From etl_daily_cardstatus )
Where seq=1 ) a Where a.card_no=b.card_no )
Where card_no In (Select a.card_no From etl_daily_cardstatus a)
因为a表card_no不是主键了,所以改成这么写,第一次执行要了0.39秒,后面执行在0.016-0.03秒之间。
第二种写法应该是 in 这个where条件起了很大的作用。