How to auto run oracle stored procedure

All we need is an easy explanation of the problem, so here it is.

Is there any possibility to auto run procedure after a specific time/date?
For example I want to auto run this stored procedure after 2 days:

CREATE OR REPLACE PROCEDURE deleteresetlinks
AS BEGIN  
  DELETE FROM passwordresetlink WHERE date_created <= TRUNC(SYSDATE) - 3;
END;

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

You can create a scheduler job along the lines of this:

begin
    dbms_scheduler.create_job
    ( job_name        => 'DELETE_RESET_LINKS'
    , job_type        => 'PLSQL_BLOCK'
    , job_action      => 'begin deleteresetlinks; end;'
    , start_date      => trunc(sysdate) +2
    , repeat_interval => 'freq=daily; interval=2;'
    , enabled         => true );
end;

Query USER_SCHEDULER_JOBS to check the details, and USER_SCHEDULER_JOB_LOG and USER_SCHEDULER_JOB_RUN_DETAILS for the run history.

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply