|
-
PL/SQL script to delete millions of rows from a table based on date
HI All
I am very new to the database stuff. Correct me if I am wrong.
Is there a possiblity to write a script in oracle which deletes the rows from a table based on the age. i.e., I want to delete the rows which are >60 days. I have a table with millions of rows in it and I want to keep only the latest two months rows. I have the following table with column names as
ERROR_IND
FEED_ID
QUEUE_ID
FEED_DT_TM -date datatype .
I have written few of the scripts to implement it.
1.DELETE FROM table_name WHERE sysdate - feed_dt_tm > 60;
2. declare
begin
create table hif_psfeed1
as
select *
from hif_psfeed
where feed_dt_tm > (sysdate-60);
drop table hif_psfeed;
alter table hif_psfeed1 rename to hif_psfeed;
end;
/
3. declare
job_delete in number;
begin
sys.dbms_job.submit
(job=>job_delete,
what=>'begin delete from hif_psfeed WHERE sysdate - feed_dt_tm >''60''; end;',
next_date=>trunc(sysdate)+1,
interval=>'trunc(sysdate)+1'
);
commit;
end;
/
The first one and second seems to take long time and I am getting errors while running the 3rd one. Please advise me on this. I need to keep running this script everyday to keep only the latest 2 months of data in the table
Thanks In advance
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|