Oracle dbms_scheduler.create_job Error - sql

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

Related

run DBMS_SCHEDULER.create_job from sys for a stored procedure owned by another schema [Oracle SQL]

I want to schedule runs to execute a stored procedure which belonged to a schema schemaA when logging in as SYS user.
The stored procedure procedureA takes in an input parameter varA. I was having some trouble running the scheduler.
BEGIN
DBMS_SCHEDULER.create_job(
job_name => 'test1',
job_type => 'STORED_PROCEDURE',
job_action => 'schemaA.procedureA(''varA''); ',
start_date => SYSTIMESTAMP,
repeat_interval => 'FREQ=minutely;BYMINUTE=0,10,20,30,40,50;BYSECOND=0',
enabled => TRUE,
comments => 'Your description of your job'
);
END;
I got error:
Error report -
ORA-27452: "schemaA.procedureA('varA'); " is an invalid name for a database object.
ORA-06512: at "SYS.DBMS_ISCHED", line 175
ORA-06512: at "SYS.DBMS_SCHEDULER", line 286
ORA-06512: at line 3
27452. 00000 - "\"%s\" is an invalid name for a database object."
*Cause: An invalid name was used to identify a database object.
*Action: Reissue the command using a valid name.
Wondering how should I fix this
You can't specify inputs in the ACTION parameter, only the name of the procedure. Use the NUMBER_OF_ARGUMENTS and ARGUMENTS parameters to specify the inputs.
See the documentation here: https://docs.oracle.com/en/database/oracle/oracle-database/19/arpls/DBMS_SCHEDULER.html#GUID-1BC57390-C756-4908-A4D8-8D1EEC236E25
See an example here: Creating a dbms_scheduler.create_job with arguments
dbms_scheduler.create_job (
job_name=>'script_dbms_scheduler_test',
job_action=>'/data/home/workflow/script_dbms_scheduler.ksh',
job_type=>'executable',
number_of_arguments=>1,
auto_drop => TRUE,
comments=> 'Run shell-script script_dbms_scheduler.ksh');
dbms_scheduler.set_job_argument_value (
job_name =>'script_dbms_scheduler_test',
argument_position => 1,
argument_value => v_text);
dbms_scheduler.enable('script_dbms_scheduler_test');

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!!

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;

Job scheduling is not working in oracle

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.

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;