• 查询表和字段有没有注释


     1 --定义一个数组类型msg_array,元素类型是varchar2,元素的长度不能超过30
     2 create or replace type msg_array is table of varchar2(30);
     3 --定义一个存储过程,查询表和字段是否有注释,参数tableNames的类型为上面定义的类型
     4 create or replace procedure testGetComments(tableNames in msg_array) is
     5   --定义变量tab_comments,记录表是否有注释,有则大于0
     6   tab_comments int := 0;
     7   --定义变量col_comments,记录没有注释的字段总数
     8   col_comments int := 0;
     9   --定义变量str,输出信息
    10   str          varchar2(100) := '';
    11   --定义变量flag,是否需要打印信息,大于0则需要打印
    12   flag         int := 0;
    13 
    14   begin
    15   
    16     --输出共有几个表(特定环境才能输出)
    17     DBMS_OUTPUT.put_line('共有:' || tableNames.COUNT || '个表');
    18     if tableNames.COUNT != 0  --如果数组长度大于0
    19     then
    20       for i in 1..tableNames.COUNT  --循环数组
    21       loop
    22 
    23         --查询没有注释的字段总数
    24         select count(*) into col_comments
    25         from user_col_comments
    26         where Table_Name = tableNames(i)
    27           and comments is null;
    28         --查询表是否有注释
    29         select count(*) into tab_comments
    30         from user_tab_comments
    31         where Table_Name = tableNames(i)
    32           and comments is null;
    33 
    34         if tab_comments > 0
    35         then
    36           flag := 1;
    37           str := '没有注释,';
    38         end if;
    39 
    40         if col_comments > 0
    41         then
    42           flag := 1;
    43           str := str || col_comments || '个字段没有注释';
    44         end if;
    45 
    46         if flag > 0
    47         then
    48           DBMS_OUTPUT.put_line('表:' || tableNames(i) || ': ' || str);
    49         end if;
    50 
    51         str := '';
    52         flag := 0;
    53       end loop;
    54     end if;
    55   end;
    56   
    57   
    58 --声明一个变量tableNames,用来放表名
    59 declare tableNames msg_array :=msg_array('tableName1','tableName2');
    60 begin
    61   --调用存储过程testGetComment
    62   testGetComments(tableNames);
    63 end;
    64 
    65 --删除存储过程
    66 drop procedure testGetComments;
    67 --删除自定义类型
    68 drop type msg_array;
    69 
    70 --------------------- 
    
    71 作者:qq_33966061 
    72 来源:CSDN 
    73 原文:https://blog.csdn.net/qq_33966061/article/details/85249408 
    74 版权声明:本文为博主原创文章,转载请附上博文链接!
     
  • 相关阅读:
    单机部署Fastfds+nginx
    day_ha配置文件
    day_1_登录接口

    表(list)
    Java基础01 ------ 从HelloWorld到面向对象
    测试V模型
    360极速模式和兼容模式区别
    初识VBS
    Bug描述规范
  • 原文地址:https://www.cnblogs.com/luhan777/p/10175265.html
Copyright © 2020-2023  润新知