Oracle 删除多表中的部分数据方法
oracle表名HT_100到HT_200 ,要删除表中一部分数据。
create or replace procedure p_delete
is
t_sql varchar2(2000);
begin
for c in (select tname from tab where tname like 'HT_%')
loop
t_sql:='delete from '||c.tname||' where to_char(location_time,''yyyymmdd'')<''20150301''';
execute immediate t_sql;
commit;
dbms_output.put_line(c.tname||'删除完成');
end loop;
end;
这个是一个存储过程,
sql>exec p_delete;
每次可以自定义 删除 多少数据表中的数据。
create or replace procedure p_del_gps_ht(a in number,b in number) is
t_sql varchar2(2000);
begin
for c in (select tname
from (select rownum sq, tname
from tab
where tname like 'GPS_HT_%'
order by tname)
where sq >= a
and sq <= b) loop
t_sql:='delete from '||c.tname||' where to_char(location_time,''yyyymmdd'')<=''20140731''';
execute immediate t_sql;
commit;
end loop;
end p_del_gps_ht;
执行命令:
#: execute p_del_gps_ht(1,10)
删除rownum 1到10的表中部分数据。
create or replace procedure p_delete
is
t_sql varchar2(2000);
begin
for c in (select tname from tab where tname like 'HT_%')
loop
t_sql:='delete from '||c.tname||' where to_char(location_time,''yyyymmdd'')<''20150301''';
execute immediate t_sql;
commit;
dbms_output.put_line(c.tname||'删除完成');
end loop;
end;
这个是一个存储过程,
执行这个过程前:先运sql>set serverout on;
不会显dbms_output.put_line输出信息。sql>exec p_delete;
每次可以自定义 删除 多少数据表中的数据。
create or replace procedure p_del_gps_ht(a in number,b in number) is
t_sql varchar2(2000);
begin
for c in (select tname
from (select rownum sq, tname
from tab
where tname like 'GPS_HT_%'
order by tname)
where sq >= a
and sq <= b) loop
t_sql:='delete from '||c.tname||' where to_char(location_time,''yyyymmdd'')<=''20140731''';
execute immediate t_sql;
commit;
end loop;
end p_del_gps_ht;
执行命令:
#: execute p_del_gps_ht(1,10)
删除rownum 1到10的表中部分数据。
目录 返回
首页