--定义一个数组类型msg_array,元素类型是varchar2,元素的长度不能超过30
create or replace type msg_array is table of varchar2(30);
--定义一个存储过程,查询表和字段是否有注释,参数tableNames的类型为上面定义的类型
create or replace procedure testGetComments(tableNames in msg_array) is
--定义变量tab_comments,记录表是否有注释,有则大于0
tab_comments int := 0;
--定义变量col_comments,记录没有注释的字段总数
col_comments int := 0;
--定义变量str,输出信息
str varchar2(100) := '';
--定义变量flag,是否需要打印信息,大于0则需要打印
flag int := 0;
begin
--输出共有几个表(特定环境才能输出)
DBMS_OUTPUT.put_line('共有:' || tableNames.COUNT || '个表');
if tableNames.COUNT != 0 --如果数组长度大于0
then
for i in 1..tableNames.COUNT --循环数组
loop
--查询没有注释的字段总数
select count(*) into col_comments
from user_col_comments
where Table_Name = tableNames(i)
and comments is null;
--查询表是否有注释
select count(*) into tab_comments
from user_tab_comments
where Table_Name = tableNames(i)
and comments is null;
if tab_comments > 0
then
flag := 1;
str := '没有注释,';
end if;
if col_comments > 0
then
flag := 1;
str := str || col_comments || '个字段没有注释';
end if;
if flag > 0
then
DBMS_OUTPUT.put_line('表:' || tableNames(i) || ': ' || str);
end if;
str := '';
flag := 0;
end loop;
end if;
end;
--声明一个变量tableNames,用来放表名
declare tableNames msg_array :=msg_array('tableName1','tableName2');
begin
--调用存储过程testGetComment
testGetComments(tableNames);
end;
--删除存储过程
drop procedure testGetComments;
--删除自定义类型
drop type msg_array;
转载地址:https://blog.csdn.net/qq_33966061/article/details/85249408