Oracle
 sql >> Base de Dados >  >> RDS >> Oracle

Oracle Create Table AS e comentários de tabela e comentários de coluna


Um método é usar dbms_metadata.get_dependent_ddl em combinação com dbms_metadata.get_ddl

Aqui está um exemplo criado usando SQL plus:
SQL> set long 1000000

SQL> create table t (x number);

Table created.

SQL> comment on column T.X IS 'this is the column comment';

Comment created.

SQL> comment on table T IS 'this is the table comment';

Comment created.

SQL> SELECT dbms_metadata.get_ddl( 'TABLE', 'T' ) || ' ' ||
  2         dbms_metadata.get_dependent_ddl( 'COMMENT', 'T', USER ) the_ddl
  3  FROM dual
  4  /

THE_DDL
--------------------------------------------------------------------------------

  CREATE TABLE "SCOTT"."T"
   (    "X" NUMBER
   ) SEGMENT CREATION DEFERRED
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  TABLESPACE "USERS"

   COMMENT ON COLUMN "SCOTT"."T"."X" IS 'this is the column comment'

   COMMENT ON TABLE "SCOTT"."T"  IS 'this is the table comment'