簡體   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