DBMS_SCHEDULER.set_job_argument_value - ORA-27473: argument does not exist - oracle

Hi I'm creating a JOB CONTROLLER to run a procedure.
JOB CONTROLLER Procedure'
CREATE OR REPLACE PROCEDURE "GCCPMAINT"."JOB_CONTROLLER" as
programTotal number;
BEGIN
dbms_scheduler.create_program (
program_name => 'PGM_CLEANSE_BRNGB',
program_type => 'STORED_PROCEDURE',
program_action => 'OPT_SALES',
number_of_arguments => 1,
enabled => FALSE);
dbms_scheduler.DEFINE_PROGRAM_ARGUMENT(
program_name=>'PGM_CLEANSE_BRNGB',
argument_name=>'card_no',
argument_position=>1,
argument_type=>'varchar2');
dbms_scheduler.enable('PGM_CLEANSE_BRNGB');
DBMS_SCHEDULER.drop_job(job_name => 'JOB_Cleanse_BRNGB', force => true);
dbms_scheduler.create_job('JOB_Cleanse_BRNGB',program_name=>'PGM_CLEANSE_BRNGB',auto_drop=> true,start_date=>SYSDATE,job_style=> 'LIGHTWEIGHT');
dbms_scheduler.set_job_argument_value(
job_name=>'JOB_Cleanse_BRNGB',
argument_name=>'card_no',---> error says here
argument_value=>'1234');
dbms_scheduler.enable('JOB_Cleanse_BRNGB');
END;
here is my program action procedure
CREATE OR REPLACE PROCEDURE "OPT_SALES"(card_no VARCHAR2)
as
BEGIN
DBMS_OUTPUT.PUT_LINE ('card-Number is'||card_no);
END;
When i try to run the job controller procedure it says error as
17:42:28 [#CALL - 0 row(s), 0.000 secs] [Error Code: 27473, SQL
State: 99999] ORA-27473: argument CARD_NO does not exist ORA-06512:
at "SYS.DBMS_ISCHED", line 244 ORA-06512: at "SYS.DBMS_SCHEDULER",
line 716 ORA-06512: at "GCCPMAINT.JOB_CONTROLLER", line 27 ORA-06512:
at line 1
I have the right argument then why it says "argument CARD_NO does not exist"
Can anybody help me please.

You can also invoke a procedure without using a program. Please take a look at this. (Also, auto_drop is true by default)
DBMS_SCHEDULER.CREATE_JOB
(
job_name => 'JOB_Cleanse_BRNGB'
,job_class => 'DEFAULT_JOB_CLASS'
,job_type => 'STORED_PROCEDURE'
,start_date => SYSDATE
,job_style => 'LIGHTWEIGHT'
,job_action => 'OPT_SALES'
,number_of_arguments => 1
);
dbms_scheduler.set_job_argument_value(
job_name=>'JOB_Cleanse_BRNGB',
argument_name=>'CARD_NO',---> error says here
argument_value=>'1234');
dbms_scheduler.enable('JOB_Cleanse_BRNGB');

Related

Procedure to move oracledb export to s3 bucket fails when ran in a job

Job fails with:
ORA-29481: Implicit results cannot be returned to client.
ORA-06512: at "SYS.DBMS_SQL", line 2832
ORA-06512: at "SYS.DBMS_SQL", line 2826
ORA-06512: at "owner.SEND_TO_S3", line 8
ORA-06512: at line 1
I can run the procedure manually(BEGIN SEND_TO_S3; END;) without errors and the db exports
show up in the s3 bucket.
****Oracle Job
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'SEND_EXP_TO_S3_JOB',
job_type => 'PLSQL_BLOCK',
job_action => 'BEGIN SEND_TO_S3; END;',
start_date => SYSTIMESTAMP,
enabled => TRUE,
repeat_interval => 'freq=weekly; byday=mon; byhour=20; byminute=40; bysecond=0;');
END;
****Oracle procedure
(If there some other way than to use a refcursor that might solve this issue as well)
CREATE OR REPLACE PROCEDURE send_to_s3
AS
rc sys_refcursor;
BEGIN
open rc for
SELECT
rdsadmin.rdsadmin_s3_tasks.upload_to_s3(
p_bucket_name => 'bucket/name',
p_prefix => 'EXP',
p_s3_prefix => '',
p_directory_name => 'DATA_PUMP_DIR') `your text`
AS TASK_ID FROM DUAL;
DBMS_SQL.RETURN_RESULT(rc);
END send_to_s3;
****The oracle error points to an outdated client but I have the latest client and I'm
not sure the scheduler uses a client.
Is there a way to get this job running correctly?

Insufficient privilege DBMS_SCHEDULER job

I have created a job in Oracle using following scheduler -
BEGIN
DBMS_SCHEDULER.create_job (
job_name => 'MY_JOB',
job_type => 'PLSQL_BLOCK',
job_action => 'BEGIN my_pkg.pull_data(''Y''); END;',
start_date => '31-AUG-21 07.00.00 PM America/New_York',
repeat_interval => 'freq=daily; byminute=0; bysecond=0;',
enabled => TRUE);
END;
/
When I am running job manually using below code -
BEGIN
DBMS_SCHEDULER.RUN_JOB(
JOB_NAME => 'MY_JOB',
USE_CURRENT_SESSION => FALSE);
END;
The job is running as expected. However, scheduled same jobs are failed again and again with below error.
ORA-01031: insufficient privileges ORA-06512: at "SCOTT.MY_PKG", line 246 ORA-06512: at line 1
Any suggestion, what I am doing wrong? I think I have sufficient privileges.
Edit - If I call, individual procedure which is used in the job, it's working as expected. I have checked the line 246, which is a select statement from a table in the same schema as job, proc and other tables used by the proc.
BEGIN my_pkg.pull_data('Y'); END;

oracle dbms_scheduler.create_job() error when executed within stored procedure

Creating job from anonymous block is working fine:
begin
SYS.DBMS_SCHEDULER.create_job(
job_name => 'test_job',
job_type => 'PLSQL_BLOCK',
job_action => 'begin null; end;',
enabled => TRUE,
auto_drop => TRUE);
end;
Result:
PL/SQL procedure successfully completed.
Creating job from stored procedure:
create or replace procedure pr_create_job is
begin
SYS.DBMS_SCHEDULER.create_job(
job_name =>'test_job',
job_type =>'PLSQL_BLOCK',
job_action =>'begin null; end;',
enabled => TRUE,
auto_drop => TRUE);
end pr_create_job;
Begin
pr_create_job;
End;
Result:
Error report - ORA-27486: insufficient privileges ORA-06512: at
"SYS.DBMS_ISCHED", line 135 ORA-06512: at "SYS.DBMS_SCHEDULER", line
271 ORA-06512: at "PR_CREATE_JOB", line 3 ORA-06512: at line 2
27486. 00000 - "insufficient privileges"
As Kaushik Nayak mentioned, CREATE JOB privilege was granted through a role and not directly to the user, granting directly to user solved this error.

SQL Exception ORA-27478: job "JOB_MIG_17602" is running during DBMS_SCHEDULER.run_job

Getting the below exception when trying to run multiple jobs in parallel. This occurs intermittently.
The point of failure is DBMS_SCHEDULER.run_job
SQL Exception ORA-27478: job "JOB_MIG_17602" is running
"ORA-06512: at "SYS.DBMS_ISCHED", line 196
ORA-06512: at "SYS.DBMS_SCHEDULER", line 48
Description of the Job:
The job invokes a stored procedure which updates a table. The same stored procedure is invoked by different instances of the job created using unique job name.
Below are the steps to run the jobs:
DBMS_SCHEDULER.create_job(
job_name => l_job_name,
job_type => 'STORED_PROCEDURE',
job_action => i_chunk_processor_name,
number_of_arguments => 2,
enabled => FALSE,
auto_drop => FALSE
);
DBMS_SCHEDULER.set_job_argument_value(job_name => l_job_name, argument_position => 1, argument_value => i_user_id);
DBMS_SCHEDULER.set_job_argument_value(job_name => l_job_name, argument_position => 2, argument_value => i_chunk_id);
DBMS_SCHEDULER.enable(l_job_name);
COMMIT;
DBMS_SCHEDULER.run_job(job_name => l_job_name, use_current_session => FALSE);
Enabling a job means it is eligible for execution. So if the scheduler coordinator picks it up and starts it before you get to the "run_job" command, then you'll get the error, eg
SQL> begin
2 DBMS_SCHEDULER.create_job(
3 job_name => 'XXX',
4 job_type => 'PLSQL_BLOCK',
5 job_action => 'begin dbms_lock.sleep(60); end;',
6 enabled => FALSE,
7 auto_drop => FALSE
8 );
9 end;
10 /
PL/SQL procedure successfully completed.
SQL> exec DBMS_SCHEDULER.enable('XXX');
PL/SQL procedure successfully completed.
-- I wait for a few seconds
--
SQL> exec DBMS_SCHEDULER.run_job(job_name => 'XXX', use_current_session => FALSE);
BEGIN DBMS_SCHEDULER.run_job(job_name => 'XXX', use_current_session => FALSE); END;
*
ERROR at line 1:
ORA-27478: job "MCDONAC"."XXX" is running
ORA-06512: at "SYS.DBMS_ISCHED", line 238
ORA-06512: at "SYS.DBMS_SCHEDULER", line 568
ORA-06512: at line 1
If you are enabling it, you should not need an explicit run_job request.

Oracle scheduler error: Security Group ID (your workspace identity) is invalid

I am trying to create oracle scheduler job (send mail) by pl/sql process (job is created on button click). It create job successfully but job always finish with error:
"ORA-20001: Security Group ID (your workspace identity) is invalid. ORA-06512: at "APEX_050100.WWV_FLOW_SECURITY", line 2939 ORA-06512: at
"APEX_050100.HTMLDB_UTIL", line 3014 ORA-06512: at line 7 ORA-06512:
at line 7.
I also have tried to set security_group_id directly (apex_util.set_security_group_id(p_security_group_id => my_worspace_id or
wwv_flow_api.set_security_group_id(p_security_group_id=>my_worspace_id) but it always finish with the same error as my sample code. When i try to create job manually in sql developer it works. But when job is created by pl/sql process it finish with the mentioned error. Job is created successfully in both cases (pl/sql process or manually) with the same parameters so i do not understand why in case when job is created by pl/sql process it finish with error.
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => '"INVERTORY"."TEST"',
job_type => 'PLSQL_BLOCK',
job_action => 'begin
for c1 in (
select workspace_id
from apex_applications
where application_id = 104 )
loop
apex_util.set_security_group_id(p_security_group_id =>
c1.workspace_id);
end loop;
HTMLDB_MAIL.SEND(
p_to => ''****.****#****.com'',
p_from => ''noreply#****.com'',
p_subj => ''test mail'',
p_body => ''komu'');
end;',
number_of_arguments => 0,
start_date => TO_TIMESTAMP_TZ('2017-08-28 10:29:57.000000000 EUROPE/PRAGUE','YYYY-MM-DD HH24:MI:SS.FF TZR'),
repeat_interval => NULL,
end_date => NULL,
enabled => TRUE,
auto_drop => FALSE,
comments => '');
DBMS_SCHEDULER.SET_ATTRIBUTE(
name => '"INVERTORY"."TEST"',
attribute => 'logging_level', value => DBMS_SCHEDULER.LOGGING_OFF);
DBMS_SCHEDULER.enable(
name => '"INVERTORY"."TEST"');
END;
Try changing this :
for c1 in (
select workspace_id
from apex_applications
where application_id = 104 )
loop
apex_util.set_security_group_id(p_security_group_id =>
c1.workspace_id);
end loop;
To this :
SELECT MAX(workspace_id)
INTO v_workspace FROM apex_applications
WHERE application_id = 104;
--set workspace - declare v_workspace above as type number
wwv_flow_api.set_security_group_id(v_workspace)
In any event, it would be better to put your logic in a package in the database and create a job with job_type => 'STORED_PROCEDURE' and call on your procedure from there.

Resources