Here is a sample PL/SQL procedure that will delete records from a table that are older than 60 days:
CREATE OR REPLACE PROCEDURE delete_old_records (table_name IN VARCHAR2)
AS
BEGIN
EXECUTE IMMEDIATE 'DELETE FROM ' || table_name || ' WHERE creation_date < SYSDATE - 60';
END;
This procedure takes the name of the table as an input and deletes all records from that table whose creation_date is more than 60 days old. The EXECUTE IMMEDIATE statement is used to dynamically generate and execute a DELETE statement.
To call this procedure, you can use the following syntax:
BEGIN
delete_old_records('my_table');
END;
No comments:
Post a Comment