5

I am working on java project in which we are getting create table ddl using get_ddl method in Oracle 12c.

For example my table name is PARENT_EMP and schema is SECONDARYUSER then I am using get_ddl method.

select dbms.get_ddl('TABLE','PARENT_EMP','SECONDARYUSER') from dual;

before executing above statement I am executing following script to ignore constrainst and table spaces from ddl.

begin
        dbms_metadata.set_transform_param (dbms_metadata.session_transform,'STORAGE',false);
        dbms_metadata.set_transform_param (dbms_metadata.session_transform,'REF_CONSTRAINTS', false);
        dbms_metadata.set_transform_param (dbms_metadata.session_transform,'TABLESPACE',false);
        dbms_metadata.set_transform_param (dbms_metadata.session_transform,'SEGMENT_ATTRIBUTES', false); 
        dbms_metadata.set_transform_param (dbms_metadata.session_transform,'CONSTRAINTS', false);           
end;

But my issue is, some of table has REFERENCE PARTITIONED and if I get ddl using get_ddl method then also I am getting foreign constraint script.

Parent table DDl is :-

 create table parent_emp(
    empno      number  primary key,
    job        varchar2(20),
    sal        number(7,2),
    deptno     number(2)
    )
    partition by list(job)
    ( partition p_job_dba values ('DBA'),
      partition p_job_mgr values ('MGR'),
     partition p_job_vp  values ('VP')
   );

Child table DDl is :

  CREATE TABLE "SECONDARYUSER"."REFERENCE_EMP" 
   (    
    "ENAME" VARCHAR2(10), 
    "EMP_ID" NUMBER, 
    "EMPNO" NUMBER, 
     CONSTRAINT "FK_EMPNO" FOREIGN KEY ("EMPNO")
      REFERENCES "SECONDARYUSER"."PARENT_EMP" ("EMPNO") ENABLE
   ) 
  PARTITION BY REFERENCE ("FK_EMPNO") 
 (PARTITION "P_JOB_DBA" , 
 PARTITION "P_JOB_MGR" , 
 PARTITION "P_JOB_VP" ) "

Please suggest how can I get child table ddl without getting foreign constraint and partitioned ddl , or how can I creating portioned on already created table using alter table. Also is there any way to get partitioned ddl using get_ddl method?

1
  • the child table ddl it's wrong, please correct it. Commented Aug 14, 2019 at 13:25

1 Answer 1

1

I just found the answer.

You are missing this declaration:

exec dbms_metadata.set_transform_param (dbms_metadata.session_transform,'PARTITIONING',false);

Include it, and it will ignore the part with 'partition'.

So, you need those ones:

exec DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'STORAGE',false);
exec DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM, 'CONSTRAINTS',false);
exec DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM, 'REF_CONSTRAINTS',false);
exec dbms_metadata.set_transform_param (dbms_metadata.session_transform,'PARTITIONING',false);
exec dbms_metadata.set_transform_param (dbms_metadata.session_transform,'TABLESPACE',false);
exec dbms_metadata.set_transform_param (dbms_metadata.session_transform,'SEGMENT_ATTRIBUTES', false);

Credits: one of the answers of this.

Sign up to request clarification or add additional context in comments.

4 Comments

I am doing same but if table has reference partitioned then getting constraint and partitioned script. how can ignore partitioned script.
Thank you this command is working . After execute this command i am getting script without partitioned but foreign key script are still coming into script.CREATE TABLE "SECONDARYUSER"."REFERENCE_EMP" ( "ENAME" VARCHAR2(10), "EMP_ID" NUMBER, "EMPNO" NUMBER, CONSTRAINT "FK_EMPNO" FOREIGN KEY ("EMPNO") REFERENCES "SECONDARYUSER"."PARENT_EMP" ("EMPNO") ENABLE )
I just edited again. Try to execute again, like in my post and see if works.
I have already use that script only PARTITIONING are missing so i have add into script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.