Job scheduling is not working in oracle - sql

Created job like below :
BEGIN
Dbms_Scheduler.create_job(
job_name => 'PROECSS_STATE'
,job_type => 'STORED_PROCEDURE'
,job_action => 'ARCHIVE_AND_DELETE' -- Procedure Name
,start_date => SYSDATE
,repeat_interval => 'freq=DAILY; byhour=13' --Added byhour
,enabled => TRUE
,comments => 'job schedule for archiving process_state');
END;
When i created the job, the time was "21-mrt-2014 12:55:55"
But nothing has happened after checking( Checked at 13:05:45).
Procedure did not run as expected.
Can any one please tell me why job has not been executed?

Replace start_date => SYSDATE with start_date => SYSTIMESTAMP.
This is only a problem on some problems. For example, the code below runs 2 jobs on Oracle 12c on Windows, but only runs the first job on 11gR2 on Solaris.
begin
dbms_scheduler.create_job('TEST_JOB1', 'PLSQL_BLOCK', 'begin null; end;'
,start_date => systimestamp, enabled => true);
dbms_scheduler.create_job('TEST_JOB2', 'PLSQL_BLOCK', 'begin null; end;'
,start_date => sysdate , enabled => true);
end;
/
--Only one job ran (on some platforms).
select * from dba_scheduler_job_run_details where job_name like 'TEST%';
I do not know why this happens. I would appreciate it if anyone could explain it.

Related

scheduled job's job action exceeds 4000 characters in oracle

I have a scheduled job that I am trying to update its job_action based on new requirements but the string now exceeds 4000 characters. Is there a way to allow the job_action to exceed 4000 characters without problems? Or what's the solution?
You must have scheduler with job_type as PLSQL_BLOCK, which allows 4000 characters in job_action.
If you want more than 4000 characters of code to execute in job than create the procedure with your code (which is more than 4000 characters) and then you need to alter the scheduler with job_type as STORED_PROCEDURE and job_action as your newly created procedure name.
Something like following(example from oracle docs):
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'update_sales',
job_type => 'STORED_PROCEDURE', -- change needed here in your case
job_action => 'OPS.SALES_PKG.UPDATE_SALES_SUMMARY', -- change needed here in your case
start_date => '28-APR-08 07.00.00 PM Australia/Sydney',
repeat_interval => 'FREQ=DAILY;INTERVAL=2', /* every other day */
end_date => '20-NOV-08 07.00.00 PM Australia/Sydney',
auto_drop => FALSE,
job_class => 'batch_update_jobs',
comments => 'My new job');
END;
/
Cheers!!

Modify DBMS_SCHEDULER job to stop running between certain hours and minutes

I need to alter a job to run between 23:00PM up till 19:45PM. I have tried the below which achieves this, but the problem with the below is that the job will always stop for 15minutes per hour, between for example 10:45 till 11:00 etc. I'm not sure if I can modify the below to solve this issue.
BEGIN
DBMS_SCHEDULER.SET_ATTRIBUTE (
name => 'MY_TEST_JOB',
attribute => 'repeat_interval',
value => 'FREQ=SECONDLY;INTERVAL=5;
BYHOUR=23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19;
BYDAY=mon,tue,wed,thu,fri,sat,sun;
BYMINUTE=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40'
);
END;
Create two schedules and combine them:
exec DBMS_SCHEDULER.CREATE_SCHEDULE('JOB_PERIOD_1',
repeat_interval => 'FREQ=SECONDLY;INTERVAL=5;BYHOUR=23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18');
exec DBMS_SCHEDULER.CREATE_SCHEDULE('JOB_PERIOD_2',
repeat_interval => 'FREQ=SECONDLY;INTERVAL=5;BYHOUR=19;BYMINUTE=0,1,2,3,4,5,[...],43,44');
BEGIN
DBMS_SCHEDULER.SET_ATTRIBUTE (
name => 'MY_TEST_JOB',
attribute => 'repeat_interval',
value => 'JOB_PERIOD_1,JOB_PERIOD_2'
);
END;
Actually I tested it only with this PL/SQL block.
DECLARE
next_run_date TIMESTAMP := TIMESTAMP '2018-02-06 19:44:00';
res INTEGER := 0;
BEGIN
FOR i IN 1..30 LOOP
DBMS_SCHEDULER.EVALUATE_CALENDAR_STRING('JOB_PERIOD_1,JOB_PERIOD_2', NULL, next_run_date, next_run_date);
DBMS_OUTPUT.PUT_LINE(next_run_date);
END LOOP;
END;

Oracle: execute a Job dbms_scheduler

I Want to execute a Scheduler in Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
I have this package:
create or replace PACKAGE "S_IN_TDK" is
procedure parseMsg;
end;
and this job
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'parseMsg',
program_name => 'S_IN_TDK.parseMsg',
repeat_interval => 'FREQ=SECONDLY;INTERVAL=10',
--job_style => 'LIGHTWEIGHT',
comments => 'Job that polls device n2 every 10 seconds');
END;
but when I run the job I got this error:
Fallo al procesar el comando SQL
- ORA-27476: "S_IN_TDK.PARSEMSG" does not exist
ORA-06512: at "SYS.DBMS_ISCHED", line 185
ORA-06512: at "SYS.DBMS_SCHEDULER", line 486
ORA-06512: at line 2
I also tried
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'parseMsg',
job_action => 'begin S_IN_TDK.parseMsg; end;',
repeat_interval => 'FREQ=SECONDLY;INTERVAL=10',
--job_style => 'LIGHTWEIGHT',
comments => 'Job that polls device n2 every 10 seconds');
END;
but then I got this error:
Informe de error -
ORA-06550: line 2, column 3:
PLS-00306: wrong number or types of arguments in call to 'CREATE_JOB'
ORA-06550: line 2, column 3:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
Parameter program_name expects the name of a scheduler PROGRAM object. If you want to run an inline program then do use job_action parameter instead:
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'parseMsg',
job_action => 'begin S_IN_TDK.parseMsg; end;',
repeat_interval => 'FREQ=SECONDLY;INTERVAL=10',
--job_style => 'LIGHTWEIGHT',
comments => 'Job that polls device n2 every 10 seconds');
END;
Note that job_action expects a complete PL/SQL block as input.
DBMS_SCHEDULER.CREATE_JOB has three required parameters: job_name, job_type, and job_action. Add job_type => 'PLSQL_BLOCK', and also add enabled => true, to make the job run immediately.
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'parseMsg',
job_type => 'PLSQL_BLOCK',
job_action => 'begin S_IN_TDK.parseMsg; end;',
repeat_interval => 'FREQ=SECONDLY;INTERVAL=10',
--job_style => 'LIGHTWEIGHT',
enabled => true,
comments => 'Job that polls device n2 every 10 seconds');
END;
/
Use this query to check the job status:
select *
from dba_scheduler_job_run_details
where job_name = 'PARSEMSG'
order by log_date desc;

Oracle dbms_scheduler.create_job Error

I am trying to create a simple scheduled event in an oracle 10g database. I have been trying to use dbms_scheduler.create_job. Here is the script I wrote:
begin dbms_scheduler.create_job (
job_name => 'disengagementChecker',
job_type => 'PLSQL_BLOCK',
job_action => 'INSERT INTO
PatientClassRelObs(patientClassID,observationTypeID) VALUES (1, 11)',
start_date => SYSDATE,
repeat_interval => 'FREQ=MINUTELY;INTERVAL=1',
comments => 'Iam tesing scheduler'); end;
When I run this, oracle throws these errors
ORA-06550: line 15, column 3:
PLS-00103: Encountered the symbol
"end-of-file" when expecting one of the following:
; The symbol
";" was substituted for "end-of-file" to continue.
I don't understand whats causes this error. Do you know what causes this error? Or why this is happening?
Thank you in advance!
-David
JOB_ACTION must be a valid PL/SQL block, not just a valid SQL statement. Use this:
job_action => '
BEGIN
INSERT INTO PatientClassRelObs(patientClassID,observationTypeID)
VALUES (1, 11);
END;',
UPDATE
Maybe this is a problem with a specific environment or some code not posted. To troubleshoot, start with something that's known to work, and add one small change at a time until something breaks.
Start with this code, using SQL*Plus.
SQL> begin
2 dbms_scheduler.create_job(
3 job_name => 'TEST_JOB',
4 job_type => 'PLSQL_BLOCK',
5 job_action => 'BEGIN NULL; END;',
6 start_date => systimestamp,
7 enabled => true);
8 end;
9 /
PL/SQL procedure successfully completed.
SQL> select status, log_date from dba_scheduler_job_run_details where job_name = 'TEST_JOB';
STATUS LOG_DATE
------------------------------ ---------------------------------------------------------------------------
SUCCEEDED 26-MAR-14 11.37.59.533000 PM -05:00

Error calling CREATE_JOB

I have the following error in PL/SQL. I am not able to know what the error is. Please help me.
SQL> BEGIN
2 DBMS_SCHEDULER.CREATE_JOB
3 (
4 JOB_NAME => 'TESTINGFILE'
5 ,COMMENTS =>'TEST'
6 );
7 END;
8 /
DBMS_SCHEDULER.CREATE_JOB
*
ERROR at line 2:
ORA-06550: line 2, column 1:
PLS-00306: wrong number or types of arguments in call to 'CREATE_JOB'
ORA-06550: line 2, column 1:
PL/SQL: Statement ignored
According to the DBMS_Scheduler.Create_Job documentation, the procedure requires the job_name, job_type and job_action parameters. You've only specified job_name so you need to define the other two.
You can find DBMS_Scheduler.Create_Job examples here, here, and elsewhere.
This worked for me. I'm new to scheduling jobs but I came across this post while I was troubleshooting mine so I figured it would be good to share once I worked it out.
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'NAME_OF_PROCEDURE_JOB',
job_type => 'STORED_PROCEDURE',
job_action => 'NAME_OF_PROCEDURE',
number_of_arguments => 0,
repeat_interval => 'FREQ=DAILY;BYHOUR=23;BYMINUTE=30;',
start_date => SYSTIMESTAMP,
enabled => TRUE,
auto_drop => FALSE,
comments => 'Schedules a job to run NAME_OF_PROCEDURE at 11:30 everyday'
);
END;