views:

61

answers:

2

I'd like to create ddl scripts for most of my database objects. dbms_metadata.get_ddl works for most of the object types. For instance the following creates the ddl for a view:

select dbms_metadata.get_ddl ( 'VIEW', 'SAMPLE_VIEW') from dual

On the other hand it's not working for object_type 'JOB'. The following:

select dbms_metadata.get_ddl( 'JOB', 'SAMPLE_JOB' ) from dual

gives the following error:

ORA-31604: invalid NAME parameter "NAME" for object type JOB in function SET_FILTER
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 116
ORA-06512: at "SYS.DBMS_METADATA_INT", line 4705
ORA-06512: at "SYS.DBMS_METADATA_INT", line 8582
ORA-06512: at "SYS.DBMS_METADATA", line 2882
ORA-06512: at "SYS.DBMS_METADATA", line 2748
ORA-06512: at "SYS.DBMS_METADATA", line 4333
ORA-06512: at line 1

If I list my jobs using

select * from user_objects where object_type='JOB'

it shows SAMPLE_JOB (just like it shows SAMPLE_VIEW if filtered for object_type='VIEW').

Why is it working for VIEW (and TABLE, INDEX, TRIGGER, ...) and not for JOB?

I'm using Oracle 10g.

+1  A: 

Jobs are a DBMS_SCHEDULER concept and there is no DDL associated with them: they are created via the DBMS_SCHEDULER package.

Tony Andrews
I was hoping dbms_metadata will create a script like 'BEGIN DBMS_SCHEDULER.CREATE_JOB ( job_name => 'SAMPLE_JOB' ... )
asalamon74
@asalamon74 - please see my answer - Tony is correct that these jobs are the result of executing a dbms_scheduler call, but they are extractable by a get_ddl call to the procedural object.
dpbradley
+3  A: 

Use this:

select dbms_metadata.get_ddl( 'PROCOBJ','yourJobNameGoesHere') from dual;

(PROCOBJ's are procedural objects)

dpbradley
Thanks. This works for me.
asalamon74
An additional note - Oracle was supposed to fix this in 11.2 so it works without this magic - haven't checked.
dpbradley