我想添加多行表/列注释。
通常使用它;
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
有谁知道如何添加多行表/列注释?
答案 0 :(得分:4)
您可以简单地将换行符放在评论声明的单引号内,例如:
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
答案 1 :(得分:0)
在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'