環境:
os:red hat linux as 5
db:10.2.0.4
通常情況下我們更新資料量比較大的表的時候,通常會使用oracle中bulk collect做批量更新,但我們按照表資料行的rowid,按照rowid將表資料分成幾批,然後通過rowid更新表的資料.
1.建立表
create table tb_my_objects
asselect * from dba_objects;
2.獲取表資料的起始rowid和截止rowid
declare
l_job number;
begin
dbms_output.put_line('begin_rowid'||'------------'||'end_rowid');
for x in (select dbms_rowid.rowid_create(1,
data_object_id,
lo_fno,
lo_block,
0) min_rid,
dbms_rowid.rowid_create(1,
data_object_id,
hi_fno,
hi_block,
10000) max_rid
from (select distinct grp,
first_value(relative_fno) over(partition by grp order by relative_fno, block_id rows between unbounded preceding and unbounded following) lo_fno,
first_value(block_id) over(partition by grp order by relative_fno, block_id rows between unbounded preceding and unbounded following) lo_block,
last_value(relative_fno) over(partition by grp order by relative_fno, block_id rows between unbounded preceding and unbounded following) hi_fno,
last_value(block_id + blocks - 1) over(partition by grp order by relative_fno, block_id rows between unbounded preceding and unbounded following) hi_block,
sum(blocks) over(partition by grp) sum_blocks
from (select relative_fno,
block_id,
blocks,
trunc((sum(blocks)
over(order by relative_fno, block_id) - 0.01) /
(sum(blocks) over() / 8)) grp
from dba_extents
where segment_name = upper('tb_my_objects')
and owner = user
order by block_id)),
(select data_object_id
from user_objects
where object_name = upper('tb_my_objects'))) loop
dbms_output.put_line(x.min_rid||'----'||x.max_rid);
end loop;
end;
begin_rowid------------end_rowid
aaazwuaabaaax8aaaa----aaazwuaabaaax9/ccq
aaazwuaabaaayaaaaa----aaazwuaabaaayd/ccq
aaazwuaabaaax0aaaa----aaazwuaabaaax1/ccq
aaazwuaabaaax2aaaa----aaazwuaabaaax3/ccq
aaazwuaabaaaxuiaaa----aaazwuaabaaaxyhccq
aaazwuaabaaax4aaaa----aaazwuaabaaax5/ccq
aaazwuaabaaax+aaaa----aaazwuaabaaax//ccq
aaazwuaabaaax6aaaa----aaazwuaabaaax7/ccq
3.更新某個rowid範圍的表資料(其他的做同樣的操作)
update tb_my_objects tt
set tt.last_ddl_time=sysdate
where rowid between 'aaazwuaabaaax8aaaa' and 'aaazwuaabaaax9/ccq';
說明:11g已經提供了dbms_parallel_execute分批處理資料的過程.
-- the end --
分段表rowid 利用ROWID 快速更新單錶記錄
對於普通表 實現 update t pm deposit his b set flag substr flag,1,8 4 case when term 365 then 1 else 2 end as flag where b.data date 20130101 declare cursor c...
對錶進行ROWID切片
前言 對於乙個很大的分割槽表驚喜update,delete,想要加快執行速度,可以按照分割槽,在不同的會話中對每個分割槽表單獨進行update,delete。但是對乙個很大的非分割槽表進行update,delete,如果只在乙個會話裡執行sql,很容易引起undo不夠,如果會話連線中斷,會導致大量資...
rowid高速分頁解析
分頁第一步 獲取資料實體地址 select t.rowid rid,t.lastdate from t test t order by t.lastdate desc 分頁第二步 取得最大頁數 select rownum rn,rid from select t.rowid rid,t.lastda...