是否可以创建另一个表作为CREATE TABLE AS并保留列的注释?
CREATE TABLE TABLE1_COPY AS SELECT * FROM TABLE1;
前面的语句不包括列的注释.因此,TABLE1_COPY没有列的注释.使用USER_COL_COMMENTS是在我新创建的表上重现相同注释的唯一方法吗?
解决方法
As for DMBS_MetaDATA.GET_DDL it doesn’t seem to genereate COMMENT ON
COLUMN statements unless I am missing some properties.
一种方法是将dbms_Metadata.get_dependent_ddl与dbms_Metadata.get_ddl结合使用
以下是使用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'