Oracle Create Table AS和表注释以及列注释

是否可以将另一个表创建为CREATE TABLE AS并保留列的注释?

CREATE TABLE TABLE1_COPY AS SELECT * FROM TABLE1;

上一条语句不包括列的注释。因此,TABLE1_COPY保留无列注释。是否也在使用USER_COL_COMMENTS在新创建的表上重现相同注释的唯一方法?

回答:

至于DMBS_METADATA.GET_DDL,除非我缺少一些属性,否则它似乎不会产生COMMENT ON COLUMN语句。

一种方法是结合使用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'

以上是 Oracle Create Table AS和表注释以及列注释 的全部内容, 来源链接: utcz.com/qa/411604.html

回到顶部