实验环境
搭建平台:VMware Workstation
OS:RHEL 6.10
Grid&DB:Oracle 11.2.0.4
SQL参考
create user test identified by test default tablespace users;
--先给测试用户赋权
grant dba to test;
create table tab as select * from stu.students; --任意copy一张表用来测试
create or replace procedure p_rowid(range number, id number) is
cursor cur_rowid is
-----------------------------------SQL主体-----------------------------------
select dbms_rowid.rowid_create(1,
b.data_object_id,
a.relative_fno,
a.block_id,
0) rowid1,
dbms_rowid.rowid_create(1,
b.data_object_id,
a.relative_fno,
a.block_id + blocks - 1,
999) rowid2
from dba_extents a, dba_objects b
where a.segment_name = b.object_name
and a.owner = b.owner
and b.object_name = 'TAB' --表名
and b.owner = 'TEST' --用户名
and mod(a.extent_id, range) = id;
-----------------------------------SQL主体-----------------------------------
v_sql varchar2(4000);
begin
for cur in cur_rowid loop
v_sql := 'delete tab where student_id > 200 and rowid between :1 and :2'; --可以根据自己的SQL修改此处
execute immediate v_sql
using cur.rowid1, cur.rowid2;
commit;
end loop;
end;
/
--如果要将表切分成8份,可以在8个窗口中一次执行:
begin
p_rowid(8,0);
end;
/
begin
p_rowid(8,1);
end;
/
......
begin
p_rowid(8,7);
end;
/