前段时间,自己用的表好长,列好多(这是谁设计滴)
所以给自己写了几个方法,贴出来晒晒,供以后使用:
获取列的注释
create or replace function get_column_comment(tablename in varchar2,
columnname in varchar2) return varchar2 as
v_comment user_col_comments.comments%type;
begin
select t.comments into v_comment from user_col_comments t
where t.table_name = upper(tablename)
and t.column_name = upper(columnname);
return v_comment;
end;
上边的tablename是列所在表明,上边的columnname是列名
测试一下
select get_column_comment('user_hn_3g_zgd_list_his','local_mob_times') from dual
获取表的注释
create or replace function gettc(tablename in varchar2)
return varchar2 as
v_comment user_tab_comments.comments%type;
cursor tab_cursor(tablename varchar2) is select t.comments from user_tab_comments t where t.table_name = upper(tablename);
begin
open tab_cursor(tablename);
loop
fetch tab_cursor into v_comment;
exit when tab_cursor%notfound;
dbms_output.put_line(tablename||' '||v_comment);
end loop;
close tab_cursor;
return v_comment;
end;
上边的tablename是表名
测试一下
select gettc('sql_template_set') from dual;
还有一个自己用着玩滴
-- 用户table 列参数
create or replace function getucc(columnname in varchar2)
return varchar2 as
v_comment user_col_comments.comments%type;
cursor col_cursor(columnname varchar2) is select t.comments from user_col_comments t where t.table_name = upper('user_hn_3g_zgd_list_his') and t.column_name = upper(columnname);
begin
open col_cursor(columnname);
loop
fetch col_cursor into v_comment;
exit when col_cursor%notfound;
dbms_output.put_line(columnname||' '||v_comment);
end loop;
close col_cursor;
return v_comment;
end;
标签:comment,cursor,tablename,comments,注释,获取,varchar2,oracle,col From: https://blog.51cto.com/u_2465818/6209753