Using dbms_scheduler to run a program - oracle

I am trying to run a program using scheduler job.My code goes as follows:
--Program
BEGIN
dbms_scheduler.create_program (
program_name => 'firstprogram',
program_type => 'PLSQL_BLOCK',
program_action => 'BEGIN Execute immediate ''Create table xyz(id int, name varchar2(10))''; end;',
enabled => TRUE,
comments => 'First program');
END;
/
--Schedule
BEGIN
DBMS_SCHEDULER.create_schedule (
schedule_name => 'firstschedule',
start_date => SYSTIMESTAMP,
repeat_interval => 'freq=daily; byhour=14; byminute=25',
end_date => NULL,
comments => 'Repeats daily');
END;
/
--Job
BEGIN
dbms_scheduler.create_job (
job_name => 'firstjob',
program_name => 'firstprogram',
schedule_name => 'firstschedule',
enabled => TRUE,
comments => 'Use firstprogram and FirstSchedule');
END;
/
All these code blocks compile without showing any errors. But the table xyz is not created in the specified time. Can anyone explain me why? I am using Oracle.

Related

DBMS Scheduler error: ORA-27367: program "Schema.PROG_programname" associated with this job is disabled

I have created an oracle job using dbms scheduler.But the status gets failed in the execution. It gives the following error. 'ORA-27367: program "Schema.PROG_SIXMONTHPRIORITY" associated with this job is disabled' But I do not have disabled the job. 'program_action => 'SIXMONTHPRIORITY'' is a procedure that I have created in the schema. When I execute that procedure separately, it gets executed.
BEGIN
DBMS_SCHEDULER.CREATE_PROGRAM (
program_name => 'PROG_SIXMONTHPRIORITY',
program_action => 'SIXMONTHPRIORITY',
program_type => 'STORED_PROCEDURE');
END;
BEGIN
DBMS_SCHEDULER.CREATE_SCHEDULE (
schedule_name => 'P_SCHEDULE_3',
start_date => SYSTIMESTAMP,
repeat_interval => 'FREQ= MINUTELY; INTERVAL=30; BYMONTHDAY=19; BYHOUR=13',
end_date => SYSTIMESTAMP + INTERVAL '1' day,
comments => 'Every 30 minutes');
END;
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'CAL_SIX_MON_PRIORITY_3',
program_name => 'PROG_SIXMONTHPRIORITY',
schedule_name => 'P_SCHEDULE_3');
END;
Can anyone identify the reason for this error?
The Scheduler objects that you created can also be separately enabled or disabled. Make sure to specify "enabled => true" when creating scheduler objects:
BEGIN
DBMS_SCHEDULER.CREATE_PROGRAM (
program_name => 'PROG_SIXMONTHPRIORITY',
program_action => 'SIXMONTHPRIORITY',
program_type => 'STORED_PROCEDURE',
enabled => true);
END;
BEGIN
DBMS_SCHEDULER.CREATE_SCHEDULE (
schedule_name => 'P_SCHEDULE_3',
start_date => SYSTIMESTAMP,
repeat_interval => 'FREQ= MINUTELY; INTERVAL=30; BYMONTHDAY=19; BYHOUR=13',
end_date => SYSTIMESTAMP + INTERVAL '1' day,
comments => 'Every 30 minutes');
END;
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'CAL_SIX_MON_PRIORITY_3',
program_name => 'PROG_SIXMONTHPRIORITY',
schedule_name => 'P_SCHEDULE_3',
enabled => true);
END;
For existing objects, you can set the attributes directly:
BEGIN
DBMS_SCHEDULER.ENABLE ('PROG_SIXMONTHPRIORITY');
DBMS_SCHEDULER.ENABLE ('CAL_SIX_MON_PRIORITY_3');
END;
/

How to rename scheduler job Oracle

I would like rename scheduler job in Oracle, is it possible?
dba_scheduler_jobs(owner = "db", name = "my_job")
=> dba_scheduler_jobs(owner = "db", name = "my_own_job");
Thanks for answers.
A job is a database object, so the RENAME command works natively
SQL> begin
2 dbms_scheduler.create_job (
3 job_name => 'MY_BAD_NAME',
4 job_type => 'PLSQL_BLOCK',
5 job_action => 'begin null; end;',
6 start_date => systimestamp,
7 repeat_interval => 'freq=hourly; byminute=0; bysecond=0;',
8 enabled => true);
9 end;
10 /
PL/SQL procedure successfully completed.
SQL> rename MY_BAD_NAME to BETTER_NAME;
Table renamed.
SQL> select job_name from user_scheduler_jobs;
JOB_NAME
--------------------------------------------------------------------------------
BETTER_NAME
Instead of rename, you can create/replicate job and drop the old one.
Below, my_new_job1 has created.
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'my_new_job1',
program_name => 'my_saved_program',
repeat_interval => 'FREQ=DAILY;BYHOUR=12',
comments => 'Daily at noon');
END;
/
Below, my_new_job2 has created with same details as my_new_job1
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'my_new_job2',
program_name => 'my_saved_program',
repeat_interval => 'FREQ=DAILY;BYHOUR=12',
comments => 'Daily at noon');
END;
/
Below an old job my_new_job1 has been deleted.
BEGIN
DBMS_SCHEDULER.DROP_JOB ('my_new_job1');
END;
/

How do I schedule a stored procedure to run daily at certain time?

I am trying to schedule a stored procedure in Oracle, it should run daily at a certain time, for example at 11:59 pm
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'BLANKET_WO',
job_type => 'STORED_PROCEDURE',
job_action => 'AAKPID.BLANKET_WO_PROC',
repeat_interval => 'FREQ=DAILY;BYHOUR=23;BYMINUTE=59');
END;
/
Will this code work?
Try this, it should work:
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'BLANKET_WO',
job_type => 'STORED_PROCEDURE',
job_action => 'AAKPID.BLANKET_WO_PROC',
start_date => '16-nov-2017 11:50:00 pm',
repeat_interval => 'FREQ=DAILY;BYHOUR=23;BYMINUTE=59',
enabled => true
);
END;
/

Oracle schedule on first day of month without holidays

I need to create schedule for run jobs in oracle. It'll run at first workday of month, but excluding holidays. When first workday of month is holiday, than run should be next workday after holiday.
I managed with first workday of each month and exclude holidays, but I don't know how to set run on workday after holiday...
HOLIDAYS
DBMS_SCHEDULER.CREATE_SCHEDULE (
schedule_name => 'SCHDL_COM_HOLIDAYS',
repeat_interval => 'FREQ=YEARLY; BYDATE=0101,0111;'
);
FIRST WORKDAY
DBMS_SCHEDULER.CREATE_SCHEDULE (
schedule_name => 'SCHDL_FIRST_WD',
repeat_interval => 'FREQ=MONTHLY; BYDAY=MON,TUE,WED,THU,FRI; EXCLUDE=SCHDL_COM_HOLIDAYS; BYSETPOS=1'
);
Please follow the below steps:
1) Create schedule for all the holidays.
BEGIN
DBMS_SCHEDULER.create_schedule (
schedule_name => 'NYD_FRI',
repeat_interval => 'FREQ=YEARLY;BYDATE=1231;BYDAY=FRI',
comments => 'Friday alternative for New Year''s Day');
DBMS_SCHEDULER.create_schedule (
schedule_name => 'NYD_MON',
repeat_interval => 'FREQ=YEARLY;BYDATE=0102;BYDAY=MON',
comments => 'Monday alternative for New Year''s Day');
DBMS_SCHEDULER.create_schedule (
schedule_name => 'NewYearsDay',
repeat_interval => 'FREQ=YEARLY;BYDATE=0101;BYDAY=MON,TUE,WED,THU,FRI;'
|| 'INCLUDE=NYD_FRI,NYD_MON',
comments => 'New Year''s Day');
);
END;
/
2) Create a schedule which clubs all the schedule created above.
BEGIN
DBMS_SCHEDULER.create_schedule (
schedule_name => 'FederalHolidays',
repeat_interval => 'NewYearsDay,MartinLutherKing,PresidentsDay,',
comments => 'Federal Holidays');
END;
3) Create a job, note the “EXCLUDE” and “BYSETPOS” option
BEGIN
DBMS_SCHEDULER.create_job (
job_name => 'Run_Next_Day',
job_type => 'PLSQL_BLOCK',
job_action => 'begin Run_Next_Day; end; ',
repeat_interval => 'FREQ=MONTHLY; BYDAY=MON,TUE,WED,THU,FRI; byhour=14;byminute=30;bysecond=0; EXCLUDE=FederalHolidays; BYSETPOS=7',
enabled => TRUE,
comments => 'Skipping Holidays');
END;
/
#XING thank You for Your help. I modified your solution exactly to my needs.
The answer exactly for my problem is
New Year's Day
BEGIN
DBMS_SCHEDULER.create_schedule (
schedule_name => 'SCHD_NYD_MON',
repeat_interval => 'FREQ=YEARLY;BYDATE=0101;BYDAY=MON',
comments => 'Monday alternative for New Year''s Day');
DBMS_SCHEDULER.create_schedule (
schedule_name => 'SCHD_NEW_YEAR_DAY',
repeat_interval => 'FREQ=YEARLY;BYDATE=0101;BYDAY=MON,TUE,WED,THU,FRI;'
|| 'INCLUDE=SCHD_NYD_MON',
comments => 'New Year''s Day');
END;
/
First November's Day
BEGIN
DBMS_SCHEDULER.create_schedule (
schedule_name => 'SCHD_FNOV_MON',
repeat_interval => 'FREQ=YEARLY;BYDATE=1101;BYDAY=MON',
comments => 'Monday alternative for First November');
DBMS_SCHEDULER.create_schedule (
schedule_name => 'SCHD_FIRST_NOVEMBER',
repeat_interval => 'FREQ=YEARLY;BYDATE=1101;BYDAY=MON,TUE,WED,THU,FRI;'
|| 'INCLUDE=SCHD_FNOV_MON',
comments => 'First November''s Day');
END;
/
Federal Holidays
BEGIN
DBMS_SCHEDULER.create_schedule (
schedule_name => 'SCHD_HOLIDAYS',
repeat_interval => 'SCHD_NEW_YEAR_DAY,SCHD_FIRST_NOVEMBER',
comments => 'Federal Holidays');
END;
/
Job
BEGIN
DBMS_SCHEDULER.create_job (
job_name => 'Run_Next_Day',
job_type => 'PLSQL_BLOCK',
job_action => 'begin Run_Next_Day; end; ',
repeat_interval => 'FREQ=MONTHLY; BYDAY=MON,TUE,WED,THU,FRI;
byhour=12;byminute=0;bysecond=0;
EXCLUDE=SCHD_HOLIDAYS; BYSETPOS=1',
enabled => TRUE,
comments => 'Skipping Holidays');
END;
/

How to enable a program in oracle job schedular?

Here is my code. When I am executing execute
dbms_scheduler.run_job('daily_update_job_v1');
getting the following error
ORA-27367: program ".PROG_RESET_LOG_STATUS_V1" associated with this
job is disabled .
Any help on the following issue . Thanks
CREATE OR REPLACE PROCEDURE reset_log_status_v1 ( LOG_STATUS IN
VARCHAR2) IS
BEGIN
UPDATE (
SELECT
B.LOG_STATUS
FROM LP_QUAT_ISSUE_MST A,
LP_QUAT_ISSUE_DTL B
WHERE A.QUAT_NO = B.QUAT_NO
AND (trunc(A.QUAT_DT) + A.NO_DAY_GIVEN) <= trunc(SYSDATE)
)
SET LOG_STATUS ='N';
END;
BEGIN
DBMS_SCHEDULER.CREATE_PROGRAM (
program_name => 'PROG_RESET_LOG_STATUS_V1',
program_action => 'RESET_LOG_STATUS_V1',
program_type => 'STORED_PROCEDURE');
END;
BEGIN
DBMS_SCHEDULER.CREATE_SCHEDULE (
schedule_name => 'daily_update_v1',
start_date => SYSTIMESTAMP,
repeat_interval => 'FREQ=DAILY; INTERVAL=1',
end_date => SYSTIMESTAMP + INTERVAL '365' day,
comments => 'DAILY UPDATE');
END;
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'daily_update_job_v1',
program_name => 'PROG_RESET_LOG_STATUS_V1',
schedule_name => 'daily_update_v1'
);
END;
execute dbms_scheduler.run_job('daily_update_job_v1');
DBMS_SCHEDULER.ENABLE('PROG_RESET_LOG_STATUS_V1');

Resources