Problem with Oracle Job Scheduling

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

I have a job that refreshes a materialised view refresh group on Oracle 19c. I wanted to refresh the group daily at midnight – trunc(sysdate)? The job was made using using the following PL/SQL:

        name => 'REFG_1',
        list => '', 
        next_date => trunc(sysdate), 
        interval => 'SYSDATE + 1',
        implicit_destroy => FALSE, 
        rollback_seg => '',
        push_deferred_rpc => TRUE, 
        refresh_after_errors => FALSE);

The MVs are getting refreshed daily. However, they are refreshing at 11:26AM (this coincides with the time I originally created the job).

How do I create this job to ensure it refreshes at midnight each night?

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

Interval should be trunc(sysdate)+1 to mean midnight tomorrow.

Your next_date will be evaluated to midnight today (in the past) so the first refresh will happen ASAP. You probably want this to also be tomorrow midnight

Method 2

The next execution time (SYSDATE+1 in your case) of your job is evaluated when the previous job has been finished. Thus it will be shifted more and more.

Either use TRUNC(SYSDATE)+1 or change to modern Scheduler Jobs were you have more freedom.

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

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

Leave a Reply