Home » SQL & PL/SQL » SQL & PL/SQL » problem while create the job (oracle 10.2.0.1)
problem while create the job [message #466777] Wed, 21 July 2010 01:54 Go to next message
madhavi babburi
Messages: 117
Registered: May 2009
Location: Hyderabad
Senior Member
Hi,
I have the script of one job exists in scott schema in one database.
DECLARE
  X NUMBER;
BEGIN
  SYS.DBMS_JOB.SUBMIT
  ( job       => X 
   ,what      => 'dbms_refresh.refresh(''"SCOTT"."REFRESH_5MIN"'');'
   ,next_date => to_date('21/07/2010 20:25:11','dd/mm/yyyy hh24:mi:ss')
   ,interval  => '/*5:Mins*/ sysdate + 5/(60*24)'
   ,no_parse  => FALSE
  );
  SYS.DBMS_OUTPUT.PUT_LINE('Job Number is: ' || to_char(x));
COMMIT;
END;

REFRESH_5MIN is the refresh group in SCOTT user.
When querying DBA_JOBS, the Log_User, Priv_User, Schema_User is SCOTT only.
I have copied and run above code in another database in another schema (assume SCOTT1). I'm expecting that the job should create on SCOTT or SCOTT1. But the job get created under sys schema/user.
Please tell me what i have to do to create the job on SCOTT user?
Re: problem while create the job [message #466778 is a reply to message #466777] Wed, 21 July 2010 01:56 Go to previous messageGo to next message
Michel Cadot
Messages: 68766
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Execute your PL/SQL block in SCOTT schema and don't use SYS for this.

Regards
Michel

[Updated on: Wed, 21 July 2010 01:57]

Report message to a moderator

Re: problem while create the job [message #466849 is a reply to message #466778] Wed, 21 July 2010 08:57 Go to previous messageGo to next message
madhavi babburi
Messages: 117
Registered: May 2009
Location: Hyderabad
Senior Member
Hi,
I have one oracle table of clob column having below data as one record.
BEGIN SYS.DBMS_JOB.SUBMIT(
      JOB=> :jobno,
      WHAT=> 'dbms_refresh.refresh(''"SCOTT"."REFRESH_5MIN"'');',
      NEXT_DATE=>TO_DATE('2010-07-21 03:17:06','YYYY-MM-DD:HH24:MI:SS'),
      INTERVAL=> '/*5:Mins*/ sysdate + 5/(60*24)',
      NO_PARSE=> TRUE);
      END; 

To execute the above code, i have followed the below procedure.
1 declare
2 abc varchar2(500);
3 BEGIN
4 FOR I IN (SELECT DDL_AND_MORE_FOR_DISCUSSION FROM scott.DDI_DEPLOYMENT_TRC_DET) LOOP
5    abc := I.DDL_AND_MORE_FOR_DISCUSSION;
6    EXECUTE IMMEDIATE abc USING 50;
7 END LOOP;
8 END;

ORA-06536: IN bind variable bound to an OUT position
ORA-06512: at line 6



Whats the wrong in my execute immediate statement?

Regards,
Madhavi.
Re: problem while create the job [message #466851 is a reply to message #466849] Wed, 21 July 2010 09:03 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
The standard advice when (ab)using EXECUTE IMMEDIATE is to compose the SQL statement in a single VARCHAR2 variable
Then print the SQL before passing it to EXECUTE IMMEDIATE.
COPY the statement & PASTE into sqlplus to validate its correctness.
Re: problem while create the job [message #466854 is a reply to message #466851] Wed, 21 July 2010 09:09 Go to previous messageGo to next message
madhavi babburi
Messages: 117
Registered: May 2009
Location: Hyderabad
Senior Member
I got the below when work with sql*plus.
SQL> declare
  2  abc varchar2(500);
  3  BEGIN
  4  FOR I IN (SELECT DDL_AND_MORE_FOR_DISCUSSION FROM SCOTT.DDI_DEPLOYMENT_TRC_DET) LOOP
  5      abc := I.DDL_AND_MORE_FOR_DISCUSSION;
  6      DBMS_OUTPUT.PUT_LINE(ABC);
  7      EXECUTE IMMEDIATE abc USING 50;
  8  END LOOP;
  9  END;
 10  /
BEGIN SYS.DBMS_JOB.SUBMIT(
      JOB=> :jobno,
      WHAT=>
'dbms_refresh.refresh(''"SCOTT"."REFRESH_5MIN"'');',

NEXT_DATE=>TO_DATE('2010-07-21 03:17:06','YYYY-MM-DD:HH24:MI:SS'),

INTERVAL=> '/*5:Mins*/ sysdate + 5/(60*24)',
      NO_PARSE=> TRUE);
      END;

 

declare
*
ERROR at line 1:
ORA-06536: IN bind variable bound to an OUT position
ORA-06512: at line 7

Regards,
Madhavi.

[Updated on: Wed, 21 July 2010 09:10]

Report message to a moderator

Re: problem while create the job [message #466857 is a reply to message #466854] Wed, 21 July 2010 09:20 Go to previous messageGo to next message
Michel Cadot
Messages: 68766
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
JOB (:jobno) is an OUT parameter so you can't use 50 to bind with it.

Regards
Michel
Re: problem while create the job [message #466863 is a reply to message #466849] Wed, 21 July 2010 09:25 Go to previous messageGo to next message
flyboy
Messages: 1903
Registered: November 2006
Senior Member
madhavi babburi wrote on Wed, 21 July 2010 15:57
Whats the wrong in my execute immediate statement?

ORA-06536: IN bind variable bound to an OUT position
ORA-06512: at line 6

Do not hesitate to consult documentation when having troubles with code. It is available e.g. online on http://tahiti.oracle.com/

Some interesting 10gR2 links:
DBMS_JOB.SUBMIT procedure (note the direction of JOB parameter): http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_job.htm#i1000807

EXECUTE IMMEDIATE command (note the possibility of using USING OUT option): http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/dynamic.htm#i14500
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/executeimmediate_statement.htm#sthref2679

And, as Michel said, in this case you have to use variable instead of constant value.

[Edit: Added the last paragraph]

[Updated on: Wed, 21 July 2010 09:26]

Report message to a moderator

Re: problem while create the job [message #467000 is a reply to message #466863] Thu, 22 July 2010 00:13 Go to previous messageGo to next message
madhavi babburi
Messages: 117
Registered: May 2009
Location: Hyderabad
Senior Member
Hi,
My requirement is clone a database using DBMS_METADATA API. My procedures works fine for all object types except job. In case of job (Object type), m able to export the job but while importing got an ORA-01008 error (ORA-01008: not all variables bound).
Quote:

ORA-01008: not all variables bound
Cause: A SQL statement containing substitution variables was executed without all variables bound. All substitution variables must have a substituted value before the SQL statement is executed.
Action: In OCI, use an OBIND or OBINDN call to substitute the required values.

I don't know how to bind a value using metadata api. Can we do?

I have followed another way to recreate all jobs in the respective schemas in my destination database using dynamic sql.
In this method, the metadata of all jobs is stored in one clob column of one database table. Just i followed the below procedure to recreate the jobs in their corresponding schemas.

Below code works fine to execute the code in a clob variable.
declare
abc varchar2(500);
V_NO NUMBER ;
BEGIN
FOR I IN (SELECT DDL_AND_MORE_FOR_DISCUSSION FROM SCOTT.DDI_DEPLOYMENT_TRC_DET) LOOP
    abc := I.DDL_AND_MORE_FOR_DISCUSSION;
    DBMS_OUTPUT.PUT_LINE(ABC);
    EXECUTE IMMEDIATE abc USING OUT V_No;
END LOOP;
END;


All jobs get recreated but under sys user. Eg: I need to recreate the jobs of SCOTT in SCOTT user but above procedure should execute on another schema (SCOTT1).
Any suggestion?

I have tried by using IR method (adding 'AUTHID CURRENT_USER' to my program) but no luck.

Regards,
Madhavi.

[Updated on: Thu, 22 July 2010 00:44] by Moderator

Report message to a moderator

Re: problem while create the job [message #467009 is a reply to message #467000] Thu, 22 July 2010 00:45 Go to previous messageGo to next message
Michel Cadot
Messages: 68766
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Michel Cadot wrote on Wed, 21 July 2010 08:56
Execute your PL/SQL block in SCOTT schema and don't use SYS for this.

Regards
Michel


If you now make it in a procedure, then make SCOTT as the owner of it.

Regards
Michel

[Updated on: Thu, 22 July 2010 00:46]

Report message to a moderator

Re: problem while create the job [message #467027 is a reply to message #467009] Thu, 22 July 2010 01:17 Go to previous messageGo to next message
madhavi babburi
Messages: 117
Registered: May 2009
Location: Hyderabad
Senior Member
Hi Michel,
If i make my procedure owner as SCOTT, all (jobs under diffrent schemas also, not only scott) jobs get recreated under SCOTT. But i'm looking for jobs get recreate under their own schema (Eg: need to recreate the jobs of scott under scott, jobs of scott1 under scott1, jobs of scott2 under scott2 ......).
If i have jobs under 'N' schemas, i don't want to connect/change program owner to 'N' schemas one by one.
Finally, run the procedure in one schema but all jobs (under diffrene schemas) should get recreate under their corresponding schemas.
My procedure is...
CREATE OR REPLACE PROCEDURE SCOTT1.P_JOB
AUTHID CURRENT_USER
AS
abc varchar2(500);
V_NO NUMBER ;
BEGIN
FOR I IN (SELECT DDL_AND_MORE_FOR_DISCUSSION FROM SCOTT.DDI_DEPLOYMENT_TRC_DET) LOOP
    abc := I.DDL_AND_MORE_FOR_DISCUSSION;
    DBMS_OUTPUT.PUT_LINE(ABC);
    EXECUTE IMMEDIATE abc USING OUT V_No;
END LOOP;
END;

Regards,
Madhavi.

[Updated on: Thu, 22 July 2010 01:19]

Report message to a moderator

Re: problem while create the job [message #467032 is a reply to message #467027] Thu, 22 July 2010 01:28 Go to previous messageGo to next message
Michel Cadot
Messages: 68766
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Post a working Test case: create table and insert statements then we will be able work with your table and data.

Regards
Michel

Re: problem while create the job [message #467070 is a reply to message #467032] Thu, 22 July 2010 03:54 Go to previous messageGo to next message
madhavi babburi
Messages: 117
Registered: May 2009
Location: Hyderabad
Senior Member
Hi,
CREATE TABLE SCOTT.DDI_DEPLOYMENT_TRC_DET
(
  DEPLOYMENT_ID                NUMBER(38)       NOT NULL,
  DEPLOYMENT_STEP              NUMBER(38)       NOT NULL,
  OBJ_ID                       NUMBER(38),
  ORACLE_USR                   VARCHAR2(32 BYTE) NOT NULL,
  OS_USR                       VARCHAR2(32 BYTE) NOT NULL,
  APP                          VARCHAR2(500 BYTE),
  DDL_AND_MORE_FOR_DISCUSSION  CLOB
);

Insert into SCOTT.DDI_DEPLOYMENT_TRC_DET
   (DEPLOYMENT_ID, DEPLOYMENT_STEP, OBJ_ID, ORACLE_USR, OS_USR, APP, DDL_AND_MORE_FOR_DISCUSSION)
 Values
   (1, 1, 24096, 'SCOTT', 'SCOTT', 'TOAD', ' BEGIN DBMS_JOB.SUBMIT(
      JOB=> :jobno,
      WHAT=> ''dbms_refresh.refresh(''''"SCOTT"."REFRESH_5MIN"'''');'',
      NEXT_DATE=>TO_DATE(''2010-07-21 03:17:06'',''YYYY-MM-DD:HH24:MI:SS''),
      INTERVAL=> ''/*5:Mins*/ sysdate + 5/(60*24)'',
      NO_PARSE=> TRUE);
      END;');
Insert into SCOTT.DDI_DEPLOYMENT_TRC_DET
   (DEPLOYMENT_ID, DEPLOYMENT_STEP, OBJ_ID, ORACLE_USR, OS_USR, APP, DDL_AND_MORE_FOR_DISCUSSION)
 Values
   (1, 1, 24093, 'SCOTT', 'SCOTT', 'TOAD', ' BEGIN SYS.DBMS_JOB.SUBMIT(
      JOB=> :jobno,
      WHAT=> ''dbms_refresh.refresh(''''"SCOTT1"."RMS_RM_RDMP_STG_STS_T"'''');'',
      NEXT_DATE=>TO_DATE(''4000-01-01 00:00:00'',''YYYY-MM-DD:HH24:MI:SS''),
      INTERVAL=> ''sysdate + 15/(60*24)   '',
      NO_PARSE=> TRUE);
      END;');
      
Insert into SCOTT.DDI_DEPLOYMENT_TRC_DET
   (DEPLOYMENT_ID, DEPLOYMENT_STEP, OBJ_ID, ORACLE_USR, OS_USR, APP, DDL_AND_MORE_FOR_DISCUSSION)
 Values
   (1, 1, 24094, 'SCOTT', 'SCOTT', 'TOAD', ' BEGIN SYS.DBMS_JOB.SUBMIT(
      JOB=> :jobno,
      WHAT=> ''dbms_refresh.refresh(''''"SCOTT2"."SEC_ONL_USR_T"'''');'',
      NEXT_DATE=>TO_DATE(''4000-01-01 00:00:00'',''YYYY-MM-DD:HH24:MI:SS''),
      INTERVAL=> ''sysdate + 1/(60*24) '',
      NO_PARSE=> TRUE);
      END;');
COMMIT;


I'm expecting that the jobs get recreate on scott, scott1, scott2 respectively. But the procedure execute on any one schema only.

Here my idea is.. the jobs have no name (only number created automatically) like other objects. In the metadata also there is no reference of which schema object it iS.
Finally my requirement is..the jobs in destination database is same (also owner) as source database (job name might be diffrent).
Regards,
Madhavi.
Re: problem while create the job [message #467109 is a reply to message #467070] Thu, 22 July 2010 04:59 Go to previous message
Michel Cadot
Messages: 68766
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Quote:
I'm expecting that the jobs get recreate on scott, scott1, scott2 respectively.

How to know which one is for which user? ("respectivley" is meaningless in SQL or PL/SQL). Should not it be in ORACLE_USR column?
Anyway, the login/privilege/schema user are defined by the caller.
Only SYS or export/import tools using an internal package can define other users.

Regards
Michel
Previous Topic: SQL Query
Next Topic: Parallel execution of a procedure (merged)
Goto Forum:
  


Current Time: Thu Aug 21 03:07:59 CDT 2025