Oracle Comment添加表备注和列备注添加和查询comment on table or culumn


        oracle开发过程中,经常会用到comment on table is 和comment on column is来添加备注,以便与查看表和列的作用。

        添加标注备注的方法如下
  1.     --添加表备注   
  2.     COMMENT ON TABLE b_so IS '发货订单';
复制代码       添加列备注
  1.     --添加列注释    
  2. COMMENT ON column b_so.c_customerup_id IS '上级经销商'; 
  3.  
复制代码       查询表备注 
  1. --查询表备注 
  2. SELECT * FROM user_tab_comments WHERE comments IS NOT NULL;
复制代码       查询效果如下:    
                          
        查询列备注    
  1. --查询列备注    
  2. SELECT * FROM user_col_comments WHERE comments IS NOT NULL;
复制代码       列备注查询结果如下:
                            
        oracle数据库中,表备注和列备注对应的视图为user_tab_comments和user_col_comments;详细代码如下:
        表备注视图:
  1.  
  2. create or replace view sys.user_tab_comments as
  3. select o.name,
  4.        decode(o.type#, 0, 'NEXT OBJECT', 1, 'INDEX', 2, 'TABLE', 3, 'CLUSTER',
  5.                       4, 'VIEW', 5, 'SYNONYM', 'UNDEFINED'),
  6.        c.comment$
  7. from sys."_CURRENT_EDITION_OBJ" o, sys.com$ c
  8. where o.owner# = userenv('SCHEMAID')
  9.   and bitand(o.flags,128) = 0
  10.   and (o.type# in (4)                                                /* view */
  11.        or
  12.        (o.type# = 2                                                /* tables */
  13.         AND         /* excluding iot-overflow, nested or mv container tables */
  14.         not exists (select null
  15.                       from sys.tab$ t
  16.                      where t.obj# = o.obj#
  17.                        and (bitand(t.property, 512) = 512 or
  18.                             bitand(t.property, 8192) = 8192 OR
  19.                             bitand(t.property, 67108864) = 67108864))))
  20.   and o.obj# = c.obj#(+)
  21.   and c.col#(+) is null;
  22. comment on column sys.USER_TAB_COMMENTS.TABLE_NAME is 'Name of the object';
  23. comment on column sys.USER_TAB_COMMENTS.TABLE_TYPE is 'Type of the object:  "TABLE" or "VIEW"';
  24. comment on column sys.USER_TAB_COMMENTS.COMMENTS is 'Comment on the object';
  25.  
复制代码

        列备注视图:
  1. create or replace view sys.user_col_comments as
  2. select o.name, c.name, co.comment$
  3. from sys."_CURRENT_EDITION_OBJ" o, sys.col$ c, sys.com$ co
  4. where o.owner# = userenv('SCHEMAID')
  5.   and o.type# in (2, 4)
  6.   and o.obj# = c.obj#
  7.   and c.obj# = co.obj#(+)
  8.   and c.intcol# = co.col#(+)
  9.   and bitand(c.property, 32) = 0 /* not hidden column */;
  10. comment on column sys.USER_COL_COMMENTS.TABLE_NAME is 'Object name';
  11. comment on column sys.USER_COL_COMMENTS.COLUMN_NAME is 'Column name';
  12. comment on column sys.USER_COL_COMMENTS.COMMENTS is 'Comment on the column';
复制代码

        oracle数据库查询备注的常用方法:

**************oracle表备注查询(comment on table)**************

        通过表名查询表备注     
  1. --通过表名查询表    
  2. SELECT *    FROM user_tab_comments    WHERE comments IS NOT NULL    AND table_name = upper('v_fa_customer')    AND rownum = 1;
复制代码

        通过备注查表名  
  1. --通过备注查表名 
  2.    SELECT *    FROM user_tab_comments    WHERE comments = '跨级销售单';
复制代码
  
        通过表类型查备注   
  1. --通过表类型查表备注    
  2. SELECT DISTINCT table_type FROM user_tab_comments WHERE table_type=UPPER('table');
  3.  
  4. --通过表类型查表备注    
  5. SELECT DISTINCT table_type FROM user_tab_comments WHERE table_type=UPPER('view');
  6.  
复制代码


**************oracle列备注查询(comments column)**************

        通过列名查列备注
  1. --通过列名查列备注    
  2. SELECT *    FROM user_col_comments    WHERE column_name = upper('c_customerup_id')    AND comments IS NOT NULL;
复制代码
   

        通过表名查备注
  1. --通过表名查备注 
  2.    SELECT *    FROM user_col_comments    AND comments IS NOT NULL    AND table_name = upper('b_so');
复制代码
    
        通过列名查备注    
  1. --通过列名查备注
  2. SELECT *    FROM user_col_comments    WHERE comments IS NOT NULL    AND column_name =UPPER( 'docno');
复制代码

        通过备注查列名和表名
  1.     --通过备注查列名和表名 
  2.    SELECT *    FROM user_col_comments    WHERE comments = '单据类型';
复制代码

        这里是非常简单的笔记,如果大家喜欢,欢迎收藏转载,如有疑问,请留言我哦,嘿嘿,祝学习愉快!


















 

oracleCOMMENT查询TABLE开发

  • 3
    点赞
  • 33
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值