Solved

set dba job to run every 4 hours

Posted on 2012-04-11
7
694 Views
Last Modified: 2012-05-01
I want a job to run every 4 hours not every 4 hours after the previous run completed.

I am not sure what the SYSDATE should be.


SYSDATE+240/1440  this isn't what I want.
0
Comment
Question by:mw-hosting
7 Comments
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
Comment Utility
>>this isn't what I want.

That is 4 hours from now.  If that is the interval for the job, it will run every 4 hours.

What about this isn't what you want?
0
 
LVL 73

Assisted Solution

by:sdstuber
sdstuber earned 500 total points
Comment Utility
assuming you mean 00:00:00,  04:00:00,  08:00:00, 12:00:00,16:00:00, 20:00:00

try this...


trunc(sysdate)+(mod(to_char(sysdate,'hh'),6)+1)*4/24
0
 
LVL 73

Assisted Solution

by:sdstuber
sdstuber earned 500 total points
Comment Utility
also, you might want to look into using dbms_scheduler instead of dbms_job

BEGIN
    DBMS_SCHEDULER.create_job(
        job_name         => 'YOUR_EVERY_4_HOUR_JOB_NAME',
        job_type         => 'PLSQL_BLOCK',
        job_action       => 'begin null; end; ',  --- put your code here
        start_date       => TRUNC(SYSDATE)+1,  -- start tomorrow or whenever you want
        repeat_interval  => 'FREQ=daily;BYHOUR=0,4,8,12,16,20;BYMINUTE=0;BYSECOND=0',
        enabled          => TRUE,
        comments         => 'This ought to do it');
END;
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 23

Expert Comment

by:David
Comment Utility
Nice example, Sean.
0
 

Accepted Solution

by:
mw-hosting earned 0 total points
Comment Utility
I applied this:

'TRUNC(SYSDATE+4/24,''HH'')'

I don't have the option to use dbms_scheduler, thanks though.
0
 
LVL 73

Expert Comment

by:sdstuber
Comment Utility
37898716 --- this allows for drift if your process takes more than an hour to run.
0
 

Author Closing Comment

by:mw-hosting
Comment Utility
Another option that allows every 4 hours, not depended on the hour provided.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now