导出ORACLE表、字段、注释

先搜索了下,在原来基础上改改后用的,不知道为何有乱码,还有些会重复,不过把这个问题绕过去了...,可以用

先把原来的贴出来:

select  ATC.OWNER,
        atC.TABLE_NAME,
        ATC.COLUMN_NAME,
        utc.comments,
        ATC.DATA_TYPE,
        ATC.DATA_LENGTH,
        ATC.NULLABLE,
        ucc.comments
from
    (select ATC.OWNER,
            atC.TABLE_NAME,
            ATC.COLUMN_NAME,
            ATC.DATA_TYPE,
            ATC.DATA_LENGTH,
            ATC.NULLABLE
     from all_tab_columns ATC
     where ATC.owner ='USER' ) atc
left outer join all_col_comments ucc
             on atc.table_name=ucc.table_name and 
                atc.column_name=ucc.column_name
left outer join all_tab_comments utc
             on atc.table_name=utc.table_name
order by atc.table_name,atc.column_name
这里有个user,,查询哪个用户的表,就替换成哪个。

下面是我改之后的,就是在原来的基础上加了个条件,导出那些表的字段注释,另外拼成了可执行的sql,这样直接查询出来就可以执行了。

select c.a from (
select  'comment on column '|| atC.TABLE_NAME || '.' || ATC.COLUMN_NAME || ' is  ' || '#@#' || ucc.comments || '#@#' || ';' a
from
    (select ATC.OWNER,
            atC.TABLE_NAME,
            ATC.COLUMN_NAME,
            ATC.DATA_TYPE,
            ATC.DATA_LENGTH,
            ATC.NULLABLE
     from all_tab_columns ATC
     where ATC.owner ='TERM' ) atc
left outer join all_col_comments ucc
             on atc.table_name=ucc.table_name and 
                atc.column_name=ucc.column_name  
left outer join all_tab_comments utc
             on atc.table_name=utc.table_name
where ucc.comments is not null and atc.TABLE_NAME in(select a from acd_test)
order by atc.table_name,atc.column_name) c
group by c.a
having c.a not like '%??%'



你可能感兴趣的:(编程笔记)