Solved

set dba job to run every 4 hours

Posted on 2012-04-11
7
699 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)
ID: 37834515
>>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
ID: 37834523
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
ID: 37834555
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
ID: 37834850
Nice example, Sean.
0
 

Accepted Solution

by:
mw-hosting earned 0 total points
ID: 37898716
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
ID: 37898986
37898716 --- this allows for drift if your process takes more than an hour to run.
0
 

Author Closing Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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.  …
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.

939 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

8 Experts available now in Live!

Get 1:1 Help Now