Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

set dba job to run every 4 hours

Posted on 2012-04-11
7
Medium Priority
?
770 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 78

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 74

Assisted Solution

by:sdstuber
sdstuber earned 2000 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 74

Assisted Solution

by:sdstuber
sdstuber earned 2000 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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 74

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
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
Suggested Courses

916 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