Link to home
Start Free TrialLog in
Avatar of Pra4444
Pra4444Flag for United States of America

asked on

oracle job to run every thurday morning and sunday morning

All,

I want to create a job that basically exports all the data using expdb..i have created a procedure called DbExport that works perfectly fine and copies the export dump to an external disk...i want to know how i can create a job which will run on thursday and sunday early morning . I do not know how to set the interval date of the job properly...
any suggestions??

Thanks
Avatar of Sean Stuber
Sean Stuber

try this...


CASE
           WHEN NEXT_DAY(SYSDATE, 'Thurs') < NEXT_DAY(SYSDATE, 'Sun')
           THEN
               TRUNC(NEXT_DAY(SYSDATE, 'Thurs')) + 1 / 24
           ELSE
               TRUNC(NEXT_DAY(SYSDATE, 'Sun')) + 1 / 24
       END

that will generate an interval so that each run will be at either 1am Thursday or 1am Sunday
I generally wrap special case scheduling like that into a function  then call the function in the interval

especially with complicated intervals because the field can only be 200 characters
Avatar of Pra4444

ASKER

I created a function as ..

CREATE OR REPLACE FUNCTION NextExportSchedule RETURN DATE IS
BEGIN
    CASE
           WHEN NEXT_DAY(SYSDATE, 'Thurs') < NEXT_DAY(SYSDATE, 'Sun')
           THEN
               return TRUNC(NEXT_DAY(SYSDATE, 'Thurs')) + 1 / 24;
           ELSE
               return TRUNC(NEXT_DAY(SYSDATE, 'Sun')) + 1 / 24;
     END case;
END;
/

how do i call that?? from my job..

DECLARE
  X NUMBER;
BEGIN
  SYS.DBMS_JOB.SUBMIT
    ( job       => X
     ,what      => 'My ExportProcedure'
     ,next_date =>'????'
     ,interval  => '????'
     ,no_parse  => TRUE
    );
  SYS.DBMS_OUTPUT.PUT_LINE('Job Number is: ' || to_char(x));
END;
/



Avatar of Pra4444

ASKER

also if i want to call my proc at 3:00am its 3/24?? just want to make sure..thanks
ASKER CERTIFIED SOLUTION
Avatar of Sean Stuber
Sean Stuber

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Pra4444

ASKER

Thanks very much....Excellent..
glad I could help
also note,  in 10g  you have the dbms_scheduler which offers very sophisticated scheduling options.

this one wasn't too bad so dbms_job was sufficient but if your requirements but you may want to investigate the scheduler's advanced capabilities