Oracle批量删除数据脚本

Oracle批量删除数据脚本

𝓓𝓸𝓷 Lv6

Oracle批量清理数据脚本,利用游标自动化删除数据JOB

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
create sequence seq_id   
minvalue 1
maxvalue 99999999999999999999
start with 1
increment by 1
cache 20;


begin
for i in 1..1000000 loop
insert into t1 values(seq_id.nextval,'name'||i);
end loop;
end;
/



declare
cursor cur is (select structureid from t_cc_structure_bak where time >= to_date('20220301', 'yyyymmdd'));
type t1 is table of NUMBER(16) index by binary_integer;
v_t1 t1;
begin
open cur;
loop
fetch cur bulk collect into v_t1 limit 4000;
forall i in v_t1.first..v_t1.last
delete t_cc_structure_bak
where structureid=v_t1(i);
exit when cur%notfound;
commit;
end loop;
close cur;
end;

/
  • Title: Oracle批量删除数据脚本
  • Author: 𝓓𝓸𝓷
  • Created at : 2024-06-12 17:50:33
  • Updated at : 2024-07-20 05:15:41
  • Link: https://www.zhangdong.me/oracle-batch-delete-data.html
  • License: This work is licensed under CC BY-NC-SA 4.0.
评论