1. 程式人生 > >Oracle之with as和update用法

Oracle之with as和update用法

許久不用,又忘了,做個記錄

update test b set b.code=(
with t as
(select t.id,code||'_'||row_number() over(partition by code order by id) code
from test t)
select a.code from t a where a.ID=b.ID
);

很多金融統計中,語句相當複雜。有可能會update的時候索引使用不上,看執行計劃走不了hash join,資料量大的時候,適合於建立臨時表。