MIHIR KAR
asked on
Archive/Purge table data using plsql!
Hi Expert,
I wants to archive and purge my table data based on following condition, could you please guide me how to do this using rowid .
--This is based on create_daytime column
Archive_criteria --365*3
Purge_criteria -- 365*8
Please let me know if you need more info.
Thanks in Advance
Mihir
I wants to archive and purge my table data based on following condition, could you please guide me how to do this using rowid .
--This is based on create_daytime column
Archive_criteria --365*3
Purge_criteria -- 365*8
Please let me know if you need more info.
Thanks in Advance
Mihir
ASKER
HI sdstuber,
What do you want to do when you say "archive?"
-- Means i just want to took backup of the table ex: table_arc data if the create_daytime indicator more than 365*3.
Update a flag to mark inactive? --Yes
Copy to a different table? --Yes
Move to a different table? --Yes
For purge its only delete from the archive table. ex.table_arc
Thanks,
What do you want to do when you say "archive?"
-- Means i just want to took backup of the table ex: table_arc data if the create_daytime indicator more than 365*3.
Update a flag to mark inactive? --Yes
Copy to a different table? --Yes
Move to a different table? --Yes
For purge its only delete from the archive table. ex.table_arc
Thanks,
-- Means i just want to took backup of the table ex: table_arc data if the create_daytime indicator more than 365*3.
Update a flag to mark inactive? --Yes
Copy to a different table? --Yes
Move to a different table? --Yes
Those are 4 different options. You can't say yes to all of them, which one do you want?
Also a "backup" isn't a sql or pl/sql operation, you take backups with RMAN.
ASKER
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Update a flag to mark inactive?
Copy to a different table?
Move to a different table?
Something else?
For purge, simply delete the rows
delete your_table where create_daytime < sysdate - 365*8;
Create a dbms_scheduler job that runs once per day to execute the delete.
If your data is partitioned by create_daytime, you might need to drop old partitions once empty.
Depending on the criteria, you might even be able to use the drop itself to purge old data instead of delete.