This Oracle tutorial explains how to use comments within your SQL statements in Oracle/PLSQL with syntax and examples.
Did you know that you can place comments within your SQL statements in Oracle? These comments can appear on a single line or span across multiple lines. Let's look at how to do this.
There are two syntaxes that you can use to create a comment within your SQL statement in Oracle/PLSQL.
The syntax for creating a SQL comment in Oracle using -- symbol is:
In Oracle, a comment started with -- symbol must be at the end of a line in your SQL statement with a line break after it. This method of commenting can only span a single line within your SQL and must be at the end of the line.
The syntax for creating a SQL comment in Oracle using /* and */ symbols is:
In Oracle, a comment that starts with /* symbol and ends with */ and can be anywhere in your SQL statement. This method of commenting can span several lines within your SQL.
You can create a SQL comment on a single line in your SQL statement in Oracle/PLSQL.
Let's look at a SQL comment example that shows a SQL comment on its own line:
Here is a SQL comment that appears in the middle of the line:
Here is a SQL comment that appears at the end of the line:
or
In Oracle, you can create a SQL comment that spans multiple lines in your SQL statement. For example:
This SQL comment spans across multiple lines in Oracle - in this example, it spans across 4 lines.
In Oracle, you can also create a SQL comment that spans multiple lines using this syntax:
Oracle/PLSQL will assume that everything after the /* symbol is a comment until it reaches the */ symbol, even if it spans multiple lines within the SQL statement. So in this example, the SQL comment will span across 2 lines.