Using Comments within SQL in Oracle

This article is written about how to use remarks inside your SQL statements in Oracle/PLSQL with syntax and examples.

Description

Did you comprehend that you can region feedback within your SQL statements in Oracle? These comments can show up on a single line or span across more than one lines. Let’s look at how to do this.

Syntax

There are two syntaxes that you can use to create a comment inside your SQL assertion in Oracle/PLSQL.

Syntax Using — symbol

The syntax for developing a SQL comment in Oracle the use of — image is:

-- comment goes here

In Oracle, a comment began with — image should be at the quit of a line in your SQL announcement with a line damage after it. This approach of commenting can solely span a single line within your SQL and need to be at the give up of the line.

Syntax Using /* and */ symbols

The syntax for growing a SQL remark in Oracle the usage of /* and */ symbols is:

/* comment goes here */

In Oracle, a remark that starts offevolved with /* symbol and ends with */ and can be anywhere in your SQL statement. This technique of commenting can span countless strains inside your SQL.

Example – Comment on a Single Line

You can create a SQL remark on a single line in your SQL declaration in Oracle/PLSQL.

Let’s seem to be at a SQL remark instance that shows a SQL comment on its personal line:

SELECT suppliers.supplier_id
/* Author: TechOnTheNet.com */
FROM suppliers;

Here is a SQL remark that appears in the middle of the line:

SELECT  /* Author: TechOnTheNet.com */  suppliers.supplier_id
FROM suppliers;

Here is a SQL remark that seems at the quit of the line:

SELECT suppliers.supplier_id  /* Author: TechOnTheNet.com */
FROM suppliers;

or

SELECT suppliers.supplier_id  -- Author: TechOnTheNet.com
FROM suppliers;

Example – Comment on Multiple Lines

In Oracle, you can create a SQL comment that spans more than one traces in your SQL statement. For example:

SELECT suppliers.supplier_id
/*
 * Author: TechOnTheNet.com
 * Purpose: To show a comment that spans multiple lines in your SQL statement.
 */
FROM suppliers;

This SQL remark spans across a couple of lines in Oracle – in this example, it spans across four lines.

In Oracle, you can additionally create a SQL comment that spans multiple lines using this syntax:

SELECT suppliers.supplier_id /* Author: TechOnTheNet.com
Purpose: To show a comment that spans multiple lines in your SQL statement. */
FROM suppliers;

Oracle/PLSQL will assume that everything after the /* symbol is a comment until it reaches the */ symbol, even if it spans multiple strains inside the SQL statement. So in this example, the SQL remark will span throughout 2 lines.