ITPub博客

首页 > 数据库 > Oracle > [20220317]补充完善TPT 显示字段列的脚本.txt

[20220317]补充完善TPT 显示字段列的脚本.txt

原创 Oracle 作者:lfree 时间:2022-03-25 16:19:31 0 删除 编辑

[20220317]补充完善TPT 显示字段列的脚本.txt

--//tpt仅仅有comm.sql显示表注解的脚本,没有显示字段注解的脚本。在原始的comm.sql脚本增加查询字段的内容。
--//另外脚本支持模糊查询,查询最好规避它,不然输出太多。

$ cat colcomm.sql
-- Copyright 2018 Tanel Poder. All rights reserved. More info at http://tanelpoder.com
-- Licensed under the Apache License, Version 2.0. See LICENSE.txt for terms & conditions.

prompt Not listing tables without comments...
prompt Input argument owner.table_name column  or owner.table_name ''

COLUMN comm_comments HEADING COMMENTS FORMAT a120 WORD_WRAP
COLUMN comm_owner    HEADING OWNER FORMAT A20 WRAP
COLUMN comm_table_name HEADING TABLE_NAME FORMAT A30
COLUMN comm_column_name HEADING COLUMN_NAME FORMAT A30

SELECT
    owner                   comm_owner
  ,     table_name              comm_table_name
  , comments comm_comments
FROM
        all_tab_comments
WHERE
  comments is not null
AND
  upper(table_name) LIKE
        upper(CASE
          WHEN INSTR('&1','.') > 0 THEN
              SUBSTR('&1',INSTR('&1','.')+1)
          ELSE
              '&1'
          END
             ) ESCAPE '\'
AND owner LIKE
    CASE WHEN INSTR('&1','.') > 0 THEN
      UPPER(SUBSTR('&1',1,INSTR('&1','.')-1))
    ELSE
      user
    END ESCAPE '\'
/


SELECT
    owner                   comm_owner
  ,     table_name              comm_table_name
  , column_name             comm_column_name
  , comments comm_comments
FROM
        all_col_comments
WHERE
  comments is not null
AND
  upper(table_name) LIKE
        upper(CASE
          WHEN INSTR('&1','.') > 0 THEN
              SUBSTR('&1',INSTR('&1','.')+1)
          ELSE
              '&1'
          END
             ) ESCAPE '\'
AND owner LIKE
    CASE WHEN INSTR('&1','.') > 0 THEN
      UPPER(SUBSTR('&1',1,INSTR('&1','.')-1))
    ELSE
      user
    END ESCAPE '\'
and column_name like  '%'||nvl(upper('&2'),column_name)||'%'
/

--//输出例子如下:
SYS@book> @ colcomm sys.DBA_TAB_MODIFICATIONS name
Not listing tables without comments...
OWNER                TABLE_NAME                     COMMENTS
-------------------- ------------------------------ ----------------------------------------------------------
SYS                  DBA_TAB_MODIFICATIONS          Information regarding modifications to tables

OWNER                TABLE_NAME                     COLUMN_NAME                    COMMENTS
-------------------- ------------------------------ ------------------------------ ---------------------------
SYS                  DBA_TAB_MODIFICATIONS          TABLE_NAME                     Modified table
SYS                  DBA_TAB_MODIFICATIONS          PARTITION_NAME                 Modified partition
SYS                  DBA_TAB_MODIFICATIONS          SUBPARTITION_NAME              Modified subpartition


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/267265/viewspace-2884078/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
熟悉oracle相关技术,擅长sql优化,rman备份与恢复,熟悉linux shell编程。

注册时间:2008-01-03

  • 博文量
    4006
  • 访问量
    7969436