下面黄色部分修改为实际的:用户名、表名、起止时间
DECLARE
s_owner varchar2(22) := '用户名';
s_tablename varchar2(22) := '表名';
cur_date date:= to_date('20140502', 'yyyymmdd');
end_date date:= to_date('20140510', 'yyyymmdd');
BEGIN
execute immediate 'alter session set nls_date_format = ''yyyy-mm-dd hh24:mi:ss''';
while cur_date < end_date loop
begin
dbms_output.put_line('ALTER TABLE ' || s_owner || '.' || s_tablename || ' DROP PARTITION FOR(to_date(' || to_char(cur_date, 'yyyymmdd') || ', ''yyyymmdd''))');
execute immediate 'ALTER TABLE ' || s_owner || '.' || s_tablename || ' DROP PARTITION FOR(to_date(' || to_char(cur_date, 'yyyymmdd') || ', ''yyyymmdd''))';
exception
when others then
dbms_output.put_line('partition not exist for date ' || cur_date);
cur_date := cur_date + 1;
end;
end loop;
exception
when others then
dbms_output.put_line(sqlerrm);
END;