run DBMS_SCHEDULER.create_job from sys for a stored procedure owned by another schema [Oracle SQL] - 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');

Related

Oracle sql dbms_scheduler.create_job pass value to sh

I want to create simple oracle sql dbms_scheduler.create_job to run sh file:
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'my_job1',
job_type => 'excecutable',
job_action => 'bin/some/some.sh',
enabled => TRUE,
comments => 'GOOD');
END;
Before starting some.sh I want to add parameteres to sh file:
echo sayHello from $argument_from_sql
How I can get "argument_from_sql" from Oracle sql when I am starting job. Where is any possibility?
You can pass arguments, for example
DBMS_SCHEDULER.create_job(
job_name=>'MY_SHELL',
job_type=>'EXECUTABLE',
job_action=>'/path/my_shell.sh',
enabled=>false
);
DBMS_SCHEDULER.set_job_argument_value('MY_SHELL',1,'myarg');

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;

Ellucian Banner API

I am new with banner student api. When I run the code below it gives me an error:
ORA-00907: missing right parenthesis
call sb_course.f_query_one(
p_subj_code => "LMA",
p_crse_numb => "400",
p_eff_term => 201203
);
Thanks in advance for you time.
The small code snippet will not produce the error ORA-00907: missing
right parenthesis. That error is either from the context around the
code snippet, or within the code ran by calling f_query_one.
Below, I show
That double quotes around the values in the call do not work. In
Oracle double quotes are a way to specify identifiers that do not
follow the normal identifier rules. The error in this case is
ORA-06576: not a valid function or procedure name
Using single quote works when calling a procedure.
When calling a function, an into clause needs to be specified to
receive the return value. Otherwise the error ORA-06576: not a valid
function or procedure name will be raised.
In no case is ORA-00907: missing right parenthesis raised
Please look at the wider context to find the cause of your error.
The following is the interaction with SQL*Plus. SQL> is a prompt for
new commands, with the lines below with numbers for additional lines
for that one command. Everything else is printed by SQL*Plus.
Make output from the dbms_output package visible.
SQL> set serveroutput on size unlimited
Create a procedure f_query_one taking the augments from your
sample. Types are guessed based on the values passed in your
sample. Note, I do not have an SB_COURSE schema. That will be a
difference from my samples below, and your code snippet.
SQL> create or replace procedure f_query_one(p_subj_code in varchar2
2 , p_crse_numb in varchar2
3 , p_eff_term in varchar2)
4 is begin
5 dbms_output.put_line('Hello World!');
6 end f_query_one;
7 /
Procedure created.
Call as posted in your question, and find that double quotes do not
work.
SQL> call f_query_one(
2 p_subj_code => "LMA",
3 p_crse_numb => "400",
4 p_eff_term => 201203
5 );
p_subj_code => "LMA",
*
ERROR at line 2:
ORA-06576: not a valid function or procedure name
Call with single quotes. Works!
SQL> call f_query_one(p_subj_code => 'LMA'
2 , p_crse_numb => '400'
3 , p_eff_term => 201203);
Hello World!
Call completed.
Drop the procedure and create a function with the name f_query_one.
SQL> drop procedure f_query_one;
Procedure dropped.
SQL> create or replace function f_query_one(p_subj_code in varchar2
2 , p_crse_numb in varchar2
3 , p_eff_term in varchar2) return varchar2
4 is begin
5 return 'Hello World!';
6 end f_query_one;
7 /
Function created.
Call the function. But the function does exist, why does it say it does not?
SQL> call f_query_one(p_subj_code => 'LMA'
2 , p_crse_numb => '400'
3 , p_eff_term => 201203);
call f_query_one(p_subj_code => 'LMA'
*
ERROR at line 1:
ORA-06576: not a valid function or procedure name
Create a bind variable. var is a SQL*Plus command. It is part of
neither the SQL or PL/SQL languages.
SQL> var so varchar2(20)
Add an into clause to save the value in the bind variable.
SQL> call f_query_one(p_subj_code => 'LMA'
2 , p_crse_numb => '400'
3 , p_eff_term => 201203) into :so;
Call completed.
Print the bind variable. print is a SQL*Plus command. It is part of
neither the SQL or PL/SQL languages.
SQL> print so
SO
--------------------------------
Hello World!
Using single quotes should work. Are you sure the error is happening on this line? What you written in your comment looks good.
Strike that.....
You do not want to use the word "call". If you are writing in pl/sql, then drop that word. If you are writing this in sql, then use "exec" instead.