Oracle comment添加注释

Oracle 的 COMMENT 语句可以给一个列、表、视图或快照添加一个最多 2K 字节的注释。注释被存储在数据字典中,并且可以通过数据字典视图 DBA_COL_COMMENTS (列的注释)和 DBA_TAB_COMMENTS (表的注释)查看 COMMENTS 列。 COMMENT 语句的语法:


COMMENT ON TABLE tb | COLUMN tb.cols IS 'text';

其中, tb 是表的名字, cols 是表中列的名字, text 是注释的文本。可以用设置注释为空串( '' )的办法从数据库中删除一个注释,例如:


COMMENT ON TABLE employees IS '';
COMMENT ON TABLE HR.employees IS 'Employee Information';
COMMENT ON COLUMN HR.employees.FIRST_NAME IS 'Employee FIRST_NAME';

对于 SYS 用户下的表,只有拥有 ALTER 权限的普通用户才可以对其进行 COMMENT 操作。对于普通用户下的表,拥有“ COMMENT ANY TABLE ”或 ALTER 权限的普通用户都可以执行 COMMENT 操作。示例如下:


SYS@test18c> create table t as select * from dual;Table created.SYS@test18c> create user lhr33 identified by lhr;User created.SYS@test18c> grant create session to lhr33;Grant succeeded.SYS@test18c> GRANT SELECT ON sys.t to lhr33;Grant succeeded.SYS@test18c> conn lhr33/lhr
Connected.
LHR33@test18c>
LHR33@test18c> select * from sys.t;DU
--
XLHR33@test18c> comment on column sys.t.dummy is 'aa';
comment on column sys.t.dummy is 'aa'*
ERROR at line 1:
ORA-01031: insufficient privilegesLHR33@test18c> comment on table sys.t is 'aa';
comment on table sys.t is 'aa'*
ERROR at line 1:
ORA-01031: insufficient privilegesLHR33@test18c> conn / as sysdba
Connected.
SYS@test18c> grant alter on sys.t to lhr33;Grant succeeded.SYS@test18c> conn lhr33/lhr
Connected.LHR33@test18c>
LHR33@test18c> comment on table sys.t is 'aa';Comment created.LHR33@test18c> comment on column sys.t.dummy is 'aa';Comment created.LHR33@test18c> conn / as sysdba
Connected.
SYS@test18c> revoke alter on sys.t  from lhr33;Revoke succeeded.SYS@test18c> conn lhr33/lhr
Connected.
LHR33@test18c> comment on column sys.t.dummy is 'aa';
comment on column sys.t.dummy is 'aa'*
ERROR at line 1:
ORA-01031: insufficient privilegesLHR33@test18c> conn / as sysdba
Connected.
SYS@test18c> grant COMMENT ANY TABLE   to lhr33;Grant succeeded.SYS@test18c> conn lhr33/lhr
Connected.
LHR33@test18c> comment on column sys.t.dummy is 'aa';
comment on column sys.t.dummy is 'aa'*
ERROR at line 1:
ORA-01031: insufficient privilegesLHR33@test18c> comment on table sys.t is 'aa';
comment on table sys.t is 'aa'*
ERROR at line 1:
ORA-01031: insufficient privilegesLHR33@test18c> conn / as sysdba
Connected.
SYS@test18c> grant alter on sys.t to lhr33;Grant succeeded.SYS@test18c> conn lhr33/lhr
Connected.
LHR33@test18c> comment on table sys.t is 'aa';Comment created.

对于普通用户下的表,拥有 “ COMMENT ANY TABLE ”或 ALTER 权限的用户都可以执行 COMMENT 操作:


LHR33@test18c> conn lhr/lhr
Connected.
LHR@test18c> create table bb as select * from dual;Table created.LHR@test18c> conn lhr33/lhr
Connected.
LHR33@test18c>  comment on table lhr.bb is 'bb';Comment created.LHR33@test18c> select * from lhr.bb;
select * from lhr.bb*
ERROR at line 1:
ORA-01031: insufficient privilegesLHR33@test18c> conn / as sysdba
Connected.
SYS@test18c> revoke COMMENT ANY TABLE from lhr33;Revoke succeeded.SYS@test18c> conn lhr33/lhr
Connected.
LHR33@test18c>  comment on table lhr.bb is 'bb';comment on table lhr.bb is 'bb'*
ERROR at line 1:
ORA-00942: table or view does not existLHR33@test18c> conn / as sysdba
Connected.
SYS@test18c> grant select on lhr.bb to lhr33;Grant succeeded.SYS@test18c> conn lhr33/lhr
Connected.
LHR33@test18c>  comment on table lhr.bb is 'bb';comment on table lhr.bb is 'bb'*
ERROR at line 1:
ORA-01031: insufficient privilegesLHR33@test18c> conn lhr/lhr
Connected.
LHR@test18c> grant alter on lhr.bb to lhr33;Grant succeeded.LHR@test18c> conn lhr33/lhr
Connected.
LHR33@test18c>  comment on table lhr.bb is 'bb';Comment created.

视图 DBA_COL_COMMENTS 和 DBA_TAB_COMMENTS 在做开发时非常实用,举例如下:


create table SCOTT.G_PROD_USER_CONF
(func_type     VARCHAR2(20) not null,func_sub_type VARCHAR2(20) not null,userid        VARCHAR2(20) not null,username      VARCHAR2(50) not null,sendtype      VARCHAR2(20) not null,email_address VARCHAR2(500)
);
-- Add comments to the table
comment on table SCOTT.G_PROD_USER_CONF is '系统功能人员配置';
-- Add comments to the columns
comment on column SCOTT.G_PROD_USER_CONF.func_type  is '功能类型 ';
comment on column SCOTT.G_PROD_USER_CONF.func_sub_type  is '功能子类型 1=收件人 2=抄送人 3=密送人 4=发件人';
comment on column SCOTT.G_PROD_USER_CONF.userid is '员工工号';
comment on column SCOTT.G_PROD_USER_CONF.username is '员工姓名';
comment on column SCOTT.G_PROD_USER_CONF.sendtype is '发送类型1:短信2:邮件3:通知公告';
comment on column SCOTT.G_PROD_USER_CONF.email_address is '电子邮箱';
-- Grant/Revoke object privileges
grant select, insert, update, delete, references, alter, index on SCOTT.G_PROD_USER_CONF to PUBLIC;
通过视图可以查询出一些有用的SQL语句:
SELECT * FROM DBA_TAB_COMMENTS D WHERE D.TABLE_NAME = 'G_PROD_USER_CONF';
SELECT 'A.' || D.COLUMN_NAME || ',','--' || D.COMMENTS,'P_' || DTC.COLUMN_NAME || ' ' || DTC.DATA_TYPE || ',','P_' || DTC.COLUMN_NAME || ' ' || DTC.DATA_TYPE || ',' || ' --' ||D.COMMENTS 入参,'A.' || D.COLUMN_NAME || ' ' || D.COLUMN_NAME || ',' || '--' ||D.COMMENTS 查询,'P_' || D.COLUMN_NAME || ',' || '--' || D.COMMENTS 插入,'A.' || D.COLUMN_NAME || '=' || 'P_' || DTC.COLUMN_NAME || ', --' ||D.COMMENTS 更新,D.COLUMN_NAME || ', --' || D.COMMENTS,D.COMMENTS,DECODE(DTC.DATA_TYPE, 'DATE', 'DATE', '') DATA_TYPE,'--' || D.COMMENTS || CHR(10) ||' v_sql := v_sql || fun_sqlparam(p_' || D.COLUMN_NAME ||', '' and A.' || D.COLUMN_NAME || (CASEWHEN DTC.DATA_TYPE = 'VARCHAR2' THENQ'[ = ''{0}'' '); ]'ELSEQ'[ = {0} ');]'END) WHERE条件FROM DBA_COL_COMMENTS D, DBA_TAB_COLS DTCWHERE D.TABLE_NAME = DTC.TABLE_NAMEAND D.COLUMN_NAME = DTC.COLUMN_NAMEAND D.OWNER = DTC.OWNERAND D.TABLE_NAME = 'G_PROD_USER_CONF'AND D.OWNER = 'SCOTT'ORDER BY DTC.COLUMN_ID;

返回结果,只列举部分:



COMMENT

Purpose

Use the COMMENT statement to add to the data dictionary a comment about a table or table column, view, materialized view, operator, indextype, mining model, or edition.

To drop a comment from the database, set it to the empty string ' '.

See Also:

  • "Comments" for more information on associating comments with SQL statements and schema objects

  • Oracle Database Reference for information on the data dictionary views that display comments

Prerequisites

The object about which you are adding a comment must be in your own schema or:

  • To add a comment to a table, view, or materialized view, you must have COMMENT ANY TABLE system privilege.

  • To add a comment to an indextype, you must have the CREATE ANY INDEXTYPE system privilege.

  • To add a comment to an operator, you must have the CREATE ANY OPERATOR system privilege.

  • To add a comment to an edition, you must have the CREATE ANY EDITION system privilege, granted either directly or through a role.

Syntax

comment ::=

Semantics

COLUMN Clause

Specify the name of the column of a table, view, or materialized view to be commented. If you omit schema , then Oracle Database assumes the table, view, or materialized view is in your own schema.

You can view the comments on a particular table or column by querying the data dictionary views USER_TAB_COMMENTS , DBA_TAB_COMMENTS , or ALL_TAB_COMMENTS or USER_COL_COMMENTS , DBA_COL_COMMENTS , or ALL_COL_COMMENTS .

EDITION Clause

Specify the name of an existing edition to be commented.

You can query the data dictionary view ALL_EDITION_COMMENTS to view comments associated with editions that are accessible to the current user. You can query DBA_EDITION_COMMENTS to view comments associated with all editions in the database.

TABLE Clause

Specify the schema and name of the table or materialized view to be commented. If you omit schema , then Oracle Database assumes the table or materialized view is in your own schema.

Note:

In earlier releases, you could use this clause to create a comment on a materialized view. You should now use the COMMENT ON MATERIALIZED VIEW clause for materialized views.

INDEXTYPE Clause

Specify the name of the indextype to be commented. If you omit schema , then Oracle Database assumes the indextype is in your own schema.

You can view the comments on a particular indextype by querying the data dictionary views USER_INDEXTYPE_COMMENTS , DBA_INDEXTYPE_COMMENTS , or ALL_INDEXTYPE_COMMENTS .

MATERIALIZED VIEW Clause

Specify the name of the materialized view to be commented. If you omit schema , then Oracle Database assumes the materialized view is in your own schema.

You can view the comments on a particular materialized view by querying the data dictionary views USER_MVIEW_COMMENTS , DBA_MVIEW_COMMENTS , or ALL_MVIEW_COMMENTS .

MINING MODEL

Specify the name of the mining model to be commented. You must have the COMMENT ANY MINING MODEL system privilege to specify this clause.

OPERATOR Clause

Specify the name of the operator to be commented. If you omit schema , then Oracle Database assumes the operator is in your own schema.

You can view the comments on a particular operator by querying the data dictionary views USER_OPERATOR_COMMENTS , DBA_OPERATOR_COMMENTS , or ALL_OPERATOR_COMMENTS .

IS ' string '

Specify the text of the comment. Refer to "Text Literals" for a syntax description of 'string' .

Example

Creating Comments: Example  To insert an explanatory remark on the job_id column of the employees table, you might issue the following statement:

COMMENT ON COLUMN employees.job_id IS 'abbreviated job title';

To drop this comment from the database, issue the following statement:

COMMENT ON COLUMN employees.job_id IS ' ';



About Me

........................................................................................................................

● 本文作者:小麦苗,部分内容整理自网络,若有侵权请联系小麦苗删除

● 本文在itpub( http://blog.itpub.net/26736162 )、博客园( http://www.cnblogs.com/lhrbest )和个人weixin公众号( xiaomaimiaolhr )上有同步更新

● 本文itpub地址: http://blog.itpub.net/26736162

● 本文博客园地址: http://www.cnblogs.com/lhrbest

● 本文pdf版、个人简介及小麦苗云盘地址: http://blog.itpub.net/26736162/viewspace-1624453/

● 数据库笔试面试题库及解答: http://blog.itpub.net/26736162/viewspace-2134706/

● DBA宝典今日头条号地址: http://www.toutiao.com/c/user/6401772890/#mid=1564638659405826

........................................................................................................................

● QQ群号: 230161599 (满) 、618766405

● weixin群:可加我weixin,我拉大家进群,非诚勿扰

● 联系我请加QQ好友 ( 646634621 ) ,注明添加缘由

● 于 2019-04-01 06:00 ~ 2019-04-30 24:00 在魔都完成

● 最新修改时间:2019-04-01 06:00 ~ 2019-04-30 24:00

● 文章内容来源于小麦苗的学习笔记,部分整理自网络,若有侵权或不当之处还请谅解

● 版权所有,欢迎分享本文,转载请保留出处

........................................................................................................................

● 小麦苗的微店 : https://weidian.com/s/793741433?wfr=c&ifr=shopdetail

● 小麦苗出版的数据库类丛书 : http://blog.itpub.net/26736162/viewspace-2142121/

● 小麦苗OCP、OCM、高可用网络班 : http://blog.itpub.net/26736162/viewspace-2148098/

● 小麦苗腾讯课堂主页 : https://lhr.ke.qq.com/

........................................................................................................................

使用 weixin客户端 扫描下面的二维码来关注小麦苗的weixin公众号( xiaomaimiaolhr )及QQ群(DBA宝典)、添加小麦苗weixin, 学习最实用的数据库技术。

........................................................................................................................

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26736162/viewspace-2642615/,如需转载,请注明出处,否则将追究法律责任。

Oracle comment添加注释相关推荐

  1. 《Oracle comment on注释信息方法论》

    更多精彩内容尽在leonarding.blog.51cto.com <Oracle comment on注释信息方法论> 引言:在DBA日常工作中写注释信息可能会经常有,但用Oracle命 ...

  2. oracle comment on用法,《Oracle comment on注释信息方法论》

    <Oracle comment on注释信息方法论>引言:在DBA日常工作中写注释信息可能会经常有,但用Oracle命令来写和使用我想应该不是很多,其实Oracle给我们提供了非常丰富的语 ...

  3. 【Oracle】添加注释(COMMENT ON)

    在数据库中创建表以后,有时需要添加表或者列的描述信息,也就是注释.这样当后来者查看表结构时,就可以清楚的知道表或者字段的含义. 1. 语法 COMMENT ON   { TABLE [ schema. ...

  4. Oracle、MySQL添加注释(comment)

    Oracle添加注释(comment) 在Oracle数据库中,字段或列的注释是用属性comment来添加. 1. 给表添加注释: comment on table 表名 is '表的注释内容'; 实 ...

  5. Oracle给表和字段添加注释

    Oracle给表和字段添加注释. 创建"学生信息"数据表 --创建"学生信息"数据表 CREATE TABLE STUDENT_INFO ( STU_ID IN ...

  6. oracle 批量给字段加注释,Oracle给表和字段添加注释

    Oracle给表和字段添加注释. 创建"学生信息"数据表. --创建"学生信息"数据表 CREATE TABLE STUDENT_INFO ( STU_ID I ...

  7. Oracle数据库,创建表并给表、字段添加注释

    1.创建货品表 create table goods( billing_cycle_id VARCHAR2(8) NOT NULL PRIMARY KEY,   -- 账期, 其值例如:2019102 ...

  8. oracle 表名 添加注释

    oracle 表名 添加注释 COMMENT ON TABLE EMP IS '雇员表';

  9. oracle 添加删除 某个字段,并添加注释

    oracle添加某个字段,并添加注释: alter table CLUB_HOT_LEADS drop column CHLACTIVITYTYPE1; ALTER TABLE T1 ADD (A1 ...

最新文章

  1. 用ASP.NET AJAX框架扩展HTML Map控件
  2. html 表格_【HTML】3 表格标签
  3. 有艺术细胞,就一定能做个好的游戏美术吗?
  4. LiveVideoStackCon 2019上海 优秀出品人与讲师
  5. apache2 wordpress目录权限_WSL(ubuntu)的Apache2+CGI(包含CGICC)+SSL的配置
  6. 生产上oracle扩展表空间,oracle基于裸设备(raw device)扩充表空间
  7. ACwing 3. 完全背包问题(DP)
  8. Node.js 应用故障排查手册 —— 大纲与常规问题指标简介
  9. python数据可视化字段_python数据爬取及数据可视化分析
  10. openproj ubuntu安装及其输入中文变方块乱码解决
  11. IDEA配置JavaScript库
  12. 儿童手表语音物联卡贵吗?如何办理?
  13. MATLAB主题设置配色方案
  14. Event的三个阶段:CAPTURING_PHASE,AT_TARGET,BUBBLING_PHASE
  15. 上海交大团队制备全球最大规模的光量子计算芯片
  16. 打造任何地方都能使用的markdown写作软件:Typora云端化
  17. 怎么html让元素脱离文档流,子元素设置绝对定位之后脱离文档流!
  18. latex 数学符号-- 希腊字母、上下标、分数、运算符、箭头、标注、分隔符、省略号、空白间距
  19. CCF真题 ISBN号码 题解
  20. 阿里云分析型数据库MySQL版(AnalyticDB)测试初体验

热门文章

  1. 局域网使用teamviewer
  2. 前端重要信息手机号、邮箱、身份证号进行脱敏处理
  3. 预备内容:---软件安装篇(1)
  4. shell运行python脚本报错没有包_脚本安装Discuz论坛(shell + Python 实现自动化安装)...
  5. Very Deep Convolutional Networks for Large-Scale Image Recognition—中英文对照
  6. 05、postman批量测试
  7. 链接中的utm_source、utm_campaign、utm_campaign、utm_content、utm_term的含义【转】
  8. 路由器密码忘记了?三步帮你重置找回!
  9. 正则表达式匹配,2位数字,单个字符-华图在线试题修改
  10. 大数据--数据仓库--维度退化