Example:
SELECT dbms_metadata.get_ddl('TABLE', table_name, 'BOB') FROM user_tables WHERE table_name = 'APPOINTMENTS';
With various transforms renders:
create table "bob"."appointments"
(
"appointment_id" number(12,0) default "bob"."appointment_id"."nextval",
"appointment_title" varchar2(50 byte),
"appointment_priority" number generated always as <some logic> virtual
) ;
Can the default value and virtual column be stripped from the output?
In general, you can use
DBMS_METADATA.SET_TRANSFORM_PARAMto change the output for theDBMS_METADATApackage.Given the setup:
Then:
Outputs:
CREATE TABLE "FIDDLE_QANZBEWCAVFHDLPFZAAC"."appointments"
( "appointment_id" NUMBER(12,0) DEFAULT "FIDDLE_QANZBEWCAVFHDLPFZAAC"."appointment_id"."NEXTVAL",
"appointment_title" VARCHAR2(50),
"appointment_priority" NUMBER GENERATED ALWAYS AS (1) VIRTUAL
) SEGMENT CREATION DEFERRED
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS LOGGING
TABLESPACE "USERS"
and, if you apply some transform parameters:
Then the output changes to:
CREATE TABLE "FIDDLE_HKDFRKLPCSXVVQXILGQE"."appointments"
( "appointment_id" NUMBER(12,0) DEFAULT "FIDDLE_HKDFRKLPCSXVVQXILGQE"."appointment_id"."NEXTVAL",
"appointment_title" VARCHAR2(50),
"appointment_priority" NUMBER GENERATED ALWAYS AS (1) VIRTUAL
) ;
A full list of transform parameters is given in the
DBMS_METADATAdocumentation and, to answer your specific question:Using only the
DBMS_METADATApackage, no, there does not appear to be any transform parameter that would disable the output of theDEFAULTorGENERATEDclauses for a column.If you wanted to strip those clauses then you would need to do it after generating the DDL statement by rewriting the query (maybe using a simple regular expression - to look for, in the simplest cases,
DEFAULTorGENERATEDand remove everything until the next comma or theVIRTUALkeyword - or, in more complicated cases, by parsing the query to an Abstract Syntax Tree and pruning the appropriate branches).fiddle