繁体   English   中英

Oracle SQL添加多行表注释或列注释

[英]Oracle SQL adding multi-line table comment or column comment

我想添加多行表/列注释。

通常使用这个;

COMMENT ON TABLE USERS IS 'User table has the user data'

我需要的是一种在单引号内插入换行符的方法;

COMMENT ON TABLE USERS IS 'User table has the user data <smthg_here_for_new_line> 1- Name column has name <smthg_here_for_new_line> 2- Number Column has the id'

因此,表格评论将被视为;

User table has the user data
1- Name column has name
2- Number Column has the id

谁知道如何添加多行表/列注释?

您可以简单地将换行符放在注释声明的单引号内,例如:

COMMENT ON COLUMN MYTABLE.MYCOLUMN
IS
'Line 1
Line 2.
Line 3';

但请注意,在SQL Developer(可能还有其他工具)中,这并不总是按预期显示。 使用以下查询...

SELECT *
FROM USER_COL_COMMENTS
WHERE
  TABLE_NAME = 'MYTABLE'
  AND COMMENTS IS NOT NULL;

...您将在脚本输出中获得您正在寻找的内容(即,突出显示查询,右键单击,选择“运行脚本”):

TABLE_NAME COLUMN_NAME COMMENTS                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
---------- ----------- --------------
MYTABLE    MYCOLUMN    Line 1
                       Line 2
                       Line 3
MYTABLE    OTHERCOLUMN Other comments

但是在查询结果中(即突出显示查询,右键单击,选择“运行语句”),或者在打开表格并查看“列”选项卡时,完整注释将一起运行在一行上。

注意:可以查询这些注释的表是:

  • 对表的评论: USER_TAB_COMMENTS
  • 对列的评论: USER_COL_COMMENTS

在SQLPlus中,您可以在Microsoft Windows环境中使用concat和chr(10)(或chr(13)|| chr(10)):

'User table has the user data' || chr(10) || '1- Name column has name...'

此外,应该可以通过将SQLBLANKLINES设置为ON来解释换行符:

SET SQLBLANKLINES ON
COMMENT ON TABLE USERS IS 'User table has the user data
1- Name column has name
2- Number Column has the id'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM