Generating DDL script for object without schema name baked in using DBMS_METADATA.GET_DDL?

Palesz picture Palesz · Jul 21, 2011 · Viewed 8.8k times · Source

How can I generate the DDL script for my object with DBMS_METADATA.GET_DDL without the schema name baked in?

With DBMS_METADATA.GET_DDL:

CREATE TABLE "MYSCHEMA"."MYTABLE"
(
  "COL1"  NUMBER(10,0)
)

SQL Developer can do that, and I think it's also uses the DBMS_METADATA to achive this goal and generale DDL scripts.

With SQL Developer:

CREATE TABLE "MYTABLE"
(
  "COL1"  NUMBER(10,0)
)

Answer

David Norris-Hill picture David Norris-Hill · Jul 30, 2015

I recently stumbled upon the following which allows you to get ddl without the schema name.

It looks a lot simpler than any other way I have seen so far although its not included in any Oracle documentation. I spotted it in the Statements Log in SQL Developer, which generates ddl without the schema name.

DBMS_METADATA.SET_TRANSFORM_PARAM(dbms_metadata.SESSION_TRANSFORM, 'EMIT_SCHEMA', false);

You don't need to get handles or anything nasty just EXEC the above before calling DBMS_METADATA.GET_DDL