是否可以创建另一个表create table as并保留列的注释?
CREATE TABLE TABLE1_COPY AS SELECT * FROM TABLE1;
前面的语句不包括列的注释。因此,TABLE1_COPY没有列的注释。使用USER_COL_COMMENTS是否也是在新创建的表上重现相同注释的唯一方法?
发布于 2011-08-02 19:47:38
对于DMBS_METADATA.GET_DDL,它似乎不会生成对列语句的注释,除非我遗漏了一些属性。
一种方法是将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'发布于 2017-09-13 16:42:44
这是上述解决方案的简单副本,不同之处在于没有用户提供。其中TABLE_NAME是现有的表。
SELECT dbms_metadata.get_ddl( 'TABLE','TABLE_NAME' ) || ' ' || dbms_metadata.get_dependent_ddl( 'COMMENT', 'TABLE_NAME' ) the_ddl FROM dual; 如果您使用的是'Oracle SQL Developer',则不需要执行上述查询,因为您可以直接从'SQL‘选项卡本身获取结果查询。具体步骤如下:
https://stackoverflow.com/questions/6910255
复制相似问题