Oracle Create Table AS和表注释以及列注释
技术问答
240 人阅读
|
0 人回复
|
2023-09-13
|
是否可以将另一个表创建为CREATE TABLE AS并保留列的注释?8 A% R- k( R! R. ]; y) _1 k8 l A3 ~
CREATE TABLE TABLE1_COPY AS SELECT * FROM TABLE1;
; D! |$ Q, \7 Q8 |! C# y' s上一条语句不包括列的注释。因此,TABLE1_COPY保留无列注释。是否也在使用USER_COL_COMMENTS在新创建的表上重现相同注释的唯一方法?1 H0 m4 s% @% d# y* \% P3 z
- W, q! g a% O% v+ T/ E解决方案:
; w- S# q& G# L. M. c9 p8 Q ; f, j# Y' C+ h% w: Q0 Q. e% y
$ A6 v- X, v# H& J
! i% w$ V( y5 S* ?7 p6 o4 x
* i g# s" t$ n$ v至于DMBS_METADATA.GET_DDL,除非我缺少一些属性,否则它似乎不会产生COMMENT ON COLUMN语句。
! o0 T% l+ f9 Y# o( O- X3 D( A; {$ A" U9 a ]) n+ m
一种方法是结合使用dbms_metadata.get_dependent_ddl和dbms_metadata.get_ddl
* p; |7 @% n% m- k/ z( p! v& e9 v这是使用SQL plus创建的示例: j" _6 \+ L! c R: \) l6 ? E7 d; e( s
SQL> set long 1000000- W3 f# H/ {" s6 c# y
SQL> create table t (x number);% O& L: \/ y5 z
Table created.; ^3 x$ C% ]/ g2 R2 c; s. i
SQL> comment on column T.X IS 'this is the column comment';
5 |" D4 Q0 W4 h4 t8 t8 kComment created. v. b* e8 j) [0 ~% @
SQL> comment on table T IS 'this is the table comment';
0 {$ o, b1 f& ~+ p; @. @" U9 CComment created.
* j8 y5 N6 e) j2 w, M1 `+ [- bSQL> SELECT dbms_metadata.get_ddl( 'TABLE', 'T' ) || ' ' ||( E: P9 i- |/ e3 q
2 dbms_metadata.get_dependent_ddl( 'COMMENT', 'T', USER ) the_ddl
! O# I& ]( o( ^- o 3 FROM dual
0 T O) _. P; a8 t- ^" ]2 @7 V 4 /
( ~% o3 j$ S% e) J7 n. u: lTHE_DDL, X6 y* G2 ^; h6 Y, I, S
--------------------------------------------------------------------------------
& U; e6 k% R- \, \ M) s8 Q CREATE TABLE "SCOTT"."T"
' A' g- k& C/ `/ o& e3 a6 h ( "X" NUMBER
( }6 ?) Y* P( c0 U0 w ) SEGMENT CREATION DEFERRED
$ P6 p: [' F5 w" I* J3 F. L& U PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING7 X1 Q& }) h! h- p& K, e) S
TABLESPACE "USERS"
5 M* L8 j0 J% L- I6 ~ COMMENT ON COLUMN "SCOTT"."T"."X" IS 'this is the column comment'
9 D. N/ O) [. Z9 P3 g COMMENT ON TABLE "SCOTT"."T" IS 'this is the table comment' |
|
|
|
|
|