Creating oracle JOB for my stored procedure - oracle

I'm trying to create an Oracle Job for c_insert_ship_confirm_start.
BEGIN
SYS.DBMS_SCHEDULER.CREATE_JOB (
job_name => '"CRCTFDC11XRQA"."SHIP_CONFIRM_JOB"',
job_type => 'STORED_PROCEDURE',
job_action => 'c_insert_ship_confirm_start(1000,FDC,1,0)',
number_of_arguments => 0,
start_date => TO_TIMESTAMP('09-MAR-16 02.41.43.451000000 PM', 'DD-MON-RR HH.MI.SS.FF AM'),
repeat_interval => 'FREQ=DAILY;BYDAY=FRI,MON,SAT,SUN,THU,TUE,WED;BYMINUTE=5',
end_date => NULL,
job_class => 'DEFAULT_JOB_CLASS',
enabled => false,
auto_drop => true,
comments => 'SHIP_CONFIRM_JOB IN EVERY 5 MINS',
credential_name => NULL,
destination_name => NULL);
END;
Stored procedure for reference::
create or replace procedure c_insert_ship_confirm_start
(
p_commit_frequency in number default 1000,
p_whse in varchar2,
p_debug_flag in number default 0,
p_rc out number
)
while creating JOB Oracle throwing error::
ORA-27452: %s is an invalid name for a database object

Arguments are not supported with stored_procedure job type. Reference: Oracle Docs
Use plsql_block
BEGIN
sys.dbms_scheduler.create_job(job_name => '"CRCTFDC11XRQA"."SHIP_CONFIRM_JOB"',
job_type => 'PLSQL_BLOCK',
job_action => 'begin c_insert_ship_confirm_start(1000,''FDC'',1,0); end;',
number_of_arguments => 0,
start_date => to_timestamp('09-MAR-16 02.41.43.451000000 PM',
'DD-MON-RR HH.MI.SS.FF AM'),
repeat_interval => 'FREQ=DAILY;BYDAY=FRI,MON,SAT,SUN,THU,TUE,WED;BYMINUTE=5',
end_date => NULL,
job_class => 'DEFAULT_JOB_CLASS',
enabled => FALSE,
auto_drop => TRUE,
comments => 'SHIP_CONFIRM_JOB IN EVERY 5 MINS',
credential_name => NULL,
destination_name => NULL);
END;
/

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;
/

Scheduler job on Oracle does not run every second

I have a specific scheduler job in Oracle that needs to be run every second.
I tried to create this (using a procedure):
begin
sys.dbms_scheduler.create_job(job_name => 'WBC6_PUBLIC.TESTE',
job_type => 'STORED_PROCEDURE',
job_action => 'proc_insert_data',
start_date => to_date('19-02-2020 09:00:00', 'dd-mm-yyyy hh24:mi:ss'),
repeat_interval => 'Freq=Secondly;Interval=1',
end_date => to_date(null),
job_class => 'DEFAULT_JOB_CLASS',
enabled => true,
auto_drop => false,
comments => '');
end;
/
And this (using PLSQL_BLOCK):
begin
sys.dbms_scheduler.create_job(job_name => 'WBC6_PUBLIC.TESTE',
job_type => 'PLSQL_BLOCK',
job_action => 'insert into my_table (date) values (sysdate);',
start_date => to_date('19-02-2020 09:00:00', 'dd-mm-yyyy hh24:mi:ss'),
repeat_interval => 'Freq=Secondly;Interval=1',
end_date => to_date(null),
job_class => 'DEFAULT_JOB_CLASS',
enabled => true,
auto_drop => false,
comments => '');
end;
/
But the result is the same, the job runs every ~ 4 seconds.
Is there a parameter or something I can do to run every second?
I've tried something like this before and if the procedure takes or could take more than the interval, then it is impossible. Al alternative is to run the code in a continuous loop with some kind of stop mechanism inbuilt (e.g. check a stop_table.stop_column for a "stop" condition). For example:
BEGIN
LOOP
proc_insert_data; /* run your insert */
sys.DBMS_SESSION.sleep(1); /* Pause for 1 second. */
stop_condition := stop_condition + 1;
EXIT WHEN stop_condition = 900; /* exit after 15 min OR some other mechanism of your choice */
END LOOP;
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;
/

Using dbms_scheduler to run a program

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.

PLS-00103: Encountered the symbol "B" when expecting one of the following

BEGIN
DBMS_SCHEDULER.CREATE_JOB(
JOB_NAME => 'BillsDueCheck',
JOB_TYPE => 'PLSQL_BLOCK',
JOB_ACTION => 'BEGIN
UPDATE Customer C
SET C.Standing = 'B'
WHERE C.CustomerID IN (
SELECT B.CUSTOMERID
FROM Bill B
WHERE (BillDate + 60) < SYSDATE);
END;',
START_DATE => SYSTIMESTAMP,
REPEAT_INTERVAL => 'FREQ=DAILY'
END_DATE => NULL,
ENABLED => TRUE,
COMMENTS => 'Checks if the bill is overdue'
);
END;
The error occurs at the SET line I think I must be doing something wrong further up but I'm not sure.
I have tried running the job action by it's self and it works fine.
You must double your quotes around your 'B' otherwise oracle will think your string is terminated and try to interpret the B as a command.
BEGIN
DBMS_SCHEDULER.CREATE_JOB(
JOB_NAME => 'BillsDueCheck',
JOB_TYPE => 'PLSQL_BLOCK',
JOB_ACTION => 'BEGIN
UPDATE Customer C
SET C.Standing = ''B''
WHERE C.CustomerID IN (
SELECT B.CUSTOMERID
FROM Bill B
WHERE (BillDate + 60) < SYSDATE);
END;',
START_DATE => SYSTIMESTAMP,
REPEAT_INTERVAL => 'FREQ=DAILY'
END_DATE => NULL,
ENABLED => TRUE,
COMMENTS => 'Checks if the bill is overdue'
);
END;

Resources