Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle SQL adding multi-line table comment or column comment

I want to add multi-line table/column comment.

Normally this is used;

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

What I need is a way to insert the new-line inside the single quotation marks like;

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'

So that table comments will be seen like;

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

Anybody knows how add multi-line table/column comments?

like image 857
Levent Divilioglu Avatar asked Feb 20 '14 20:02

Levent Divilioglu


People also ask

How do you comment multiple lines in SQL?

Multi-line comments start with /* and end with */ . Any text between /* and */ will be ignored.

How do you add a comment to a column in SQL?

Use the COMMENT statement to add a comment about a table, view, materialized view, or column into the data dictionary. 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.

How do you comment a single line as well as multi-line code in PL SQL?

PL/SQL supports two comment styles: single-line and multi-line. Single-line comments begin with a double hyphen ( - - ) anywhere on a line and extend to the end of the line. Multi-line comments begin with a slash-asterisk ( /* ), end with an asterisk-slash ( */ ), and can span multiple lines.

What is the shortcut for comment in Oracle SQL?

In SQL Developer you can comment a line or a block using "Source -> Toggle Line Comments" (Ctrl-Slash), but it would be nice to have a button that allows you to do it not only for line or block, but also for a part of a line.


1 Answers

You can simply put line feeds inside the single-quotes of your comment declaration, for example:

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

Note, however, that in SQL Developer (and perhaps other tools) this will not always display as expected. With the following query ...

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

... you'll get exactly what you're looking for in Script Output (i.e., highlight the query, right-click, select "Run Script"):

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

But in a Query Result (i.e., highlight the query, right-click, select "Run Statement"), or when opening the table and looking at the Columns tab, the full comment will be run together on a single line.

Note: The tables in which these comments can be queried are:

  • Comments on tables: USER_TAB_COMMENTS
  • Comments on columns: USER_COL_COMMENTS
like image 148
Joe DeRose Avatar answered Sep 17 '22 13:09

Joe DeRose