Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

ORA-31603 on dbms_metadata.get_dll on FK constraint

919976Feb 25 2012 — edited Feb 25 2012
We are able to use DBMS_METADATA.GET_DDL to extract the DDL for other objects including PK constraints but not for an FK constraint. It returns ORA-31603 as seen below.
In this example we are logged in as the user U1, who has the been granted the DBA role, and are creating objects in the U1 schema to illustrate the point that we are not dealing with a permissions issue. If we do this as the SYS user we get the same error.


-- ============= START EXAMPLE =============
SQL>
SQL>show user
USER is "U1"
SQL>
SQL>-- create 1st tbl
SQL>create table U1.TBL1 (COL1 number, COL2 varchar2(10));

Table created.

SQL>
SQL>-- create PK on 1st tbl
SQL>alter table U1.TBL1
2 add constraint PK_TBL1
3 primary key (COL1);

Table altered.

SQL>
SQL>-- create 2nd tbl
SQL>create table U1.TBL2 (COL1 number, COL2 varchar2(10));

Table created.

SQL>
SQL>-- create PK on 2nd tbl
SQL>alter table U1.TBL2
2 add constraint PK_TBL2
3 primary key (COL1);

Table altered.

SQL>
SQL>-- create FK on 1st tbl referencing 2nd tbl
SQL>alter table U1.TBL1 add constraint FK1_TBL1 foreign key (COL1) references U1.TBL2 (COL1);

Table altered.

SQL>
SQL>-- generated DDL for PK on 1st tbl
SQL>select dbms_metadata.get_ddl('CONSTRAINT','PK_TBL1','U1') from dual;

DBMS_METADATA.GET_DDL('CONSTRA
________________________________________

ALTER TABLE "U1"."TBL1" ADD CONSTRAINT "PK_TBL1" PRIMARY KEY ("COL1")
USIN
SQL>
SQL>-- generated DDL for FK on 1st tbl
SQL>select dbms_metadata.get_ddl('CONSTRAINT','FK1_TBL1','U1') from dual;
ERROR:
ORA-31603: object "FK1_TBL1" of type CONSTRAINT not found in schema "U1"
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 105
ORA-06512: at "SYS.DBMS_METADATA", line 2806
ORA-06512: at "SYS.DBMS_METADATA", line 4333
ORA-06512: at line 1

no rows selected

SQL>
-- ============= END EXAMPLE =============


If anyone has any suggestions they would be greatly appreciated.
Thanks
This post has been answered by unknown-7404 on Feb 25 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 24 2012
Added on Feb 25 2012
3 comments
4,479 views