Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ORA-31603 when using DBMS_METADATA 1

Status
Not open for further replies.

Thargy

Technical User
Nov 15, 2005
1,348
GB
I am using 11g Release 11.2.0.1.0 - 64bit Production
and am logged in as SYS as SYSDBA.

I am attempting to extract the DDL for tables in several schemas. Each schema name begins with 'JOB_' and I am using this as a filtering condition.

The following sql
Code:
SELECT DBMS_METADATA.GET_DDL('TABLE',table_name) DDL_STRING,OWNER,table_name
FROM ALL_TABLES
         WHERE SUBSTR(OWNER,1,4) = 'JOB_'
           AND OWNER != 'SYS'
           AND SUBSTR(table_name,1,3) != ('MV_') --Ignore materialized views
           AND table_name NOT LIKE ('%$%') --Ignore materialized view logs
           AND table_name NOT IN (SELECT MVIEW_NAME
                                    FROM ALL_MVIEWS
                                   WHERE SUBSTR(OWNER,1,4)= 'JOB_')
      ORDER BY OWNER,table_name;

yields the following error

Code:
ORA-31603: object "CURRICULUM_DETAIL" of type TABLE not found in schema "SYS"
ORA-06512: at "SYS.DBMS_METADATA", line 2625
ORA-06512: at "SYS.DBMS_METADATA", line 2668
ORA-06512: at "SYS.DBMS_METADATA", line 2983
ORA-06512: at "SYS.DBMS_METADATA", line 3897

I have googled and found that this is a known bug. A search of the knowledge base on MOS reveals the "solution" to be

Code:
Cause
The appropriate privileges have not been granted to the schema executing the procedure as the same procedure works fine from the schema that owns the object and from SYS.
Solution

Step 1: Execute "GRANT SELECT_CATALOG_ROLE TO <schema>;" as SYS or another user with the privilege.
Step 2. Modify the procedure to include "AUTHID CURRENT_USER"

Since I am logged in as SYS, I am surprised to have any problems, as the oracle note above explicitly says that the procedure works fine from SYS.

I have also granted SELECT_CATALOG_ROLE to the user experiencing the problem, but this has had no effect.

Can anyone assist?

Regards

T
 
You are not putting a schema name in the call to get_ddl, so it will assume that the table is in the SYS schema.

Code:
 FUNCTION get_ddl (
                object_type     IN  VARCHAR2,
                name            IN  VARCHAR2,
                [b]schema          IN  VARCHAR2 DEFAULT NULL[/b],
                version         IN  VARCHAR2 DEFAULT 'COMPATIBLE',
                model           IN  VARCHAR2 DEFAULT 'ORACLE',
                transform       IN  VARCHAR2 DEFAULT 'DDL')
        RETURN CLOB;

-- GET_DEPENDENT_XML:   Return the metadata for objects dependent on a
--      base object as XML.
--      This interface is meant for casual browsing (e.g., from SQLPlus)
--      vs. the programmatic OPEN / FETCH / CLOSE interfaces above.
-- PARAMETERS:
--      object_type     - The type of object to be retrieved.
--      base_object_name- Name of the base object.
--      base_object_schema- Schema containing the base object.  [b]Defaults to
--                        the caller's schema.[/b]

 
Thanks Dagon,

I somehow felt I was missing something obvious - and I was.

I'll give it a whirl and report back shortly.

Regards

T
 
Dagon,

the following
Code:
SELECT DBMS_METADATA.GET_DDL('TABLE',table_name,schema => owner) DDL_STRING,OWNER,table_name
FROM ALL_TABLES
         WHERE SUBSTR(OWNER,1,4) = 'JOB_'
           AND OWNER != 'SYS'
           AND SUBSTR(table_name,1,3) != ('MV_') --Ignore materialized views
           AND table_name NOT LIKE ('%$%') --Ignore materialized view logs
           AND table_name NOT IN (SELECT MVIEW_NAME
                                    FROM ALL_MVIEWS
                                   WHERE SUBSTR(OWNER,1,4)= 'JOB_')
      ORDER BY OWNER,table_name;

is now bringing back results.

<doffs cap>

Regards

T
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top