oracle 获取表,列注释

前段时间,自己用的表好长,列好多(这是谁设计滴)

所以给自己写了几个方法,贴出来晒晒,供以后使用:

 

获取列的注释

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;
 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值