Comment in SQL and PL-SQL

comments

admin DataBase, Oracle

Hi DBgeek Army,
Welcome back to the world of Oracle!
Comments are very important aspects of our code. No matter which programming language we are using, we must add comments to our code so that it helps us to read and maintain while working with the same code again in future.

Comments are nothing but general statements that do not play any role in the performance and functionality but describe the purpose of the blocks/statements within the application.
There are two types of comment in SQL.

  • Single-line comment
  • Single-line comments stats with double hyphen(–) and it covers only one line. If the comment is too long we will need to break the comment into multiple lines and each line must start with double hyphen (–) or go with second method Multi-Line comment.

  • Multi-Line comment
  • There are no restrictions with Multi-Line comment. Either we can use it with a single line or multiple lines. The whole comment must start with the combination of a Forward Slash and Asterisk (/*) and must end with the combination of Asterisk and Forward Slash (*/).

See the examples below.


        SELECT
/*This is 
a multi-line comment*/
	employee_id,
	first_name,
	last_name,
	email,
	phone_number
--This is a single-line comment.
FROM
	hr.employees;
	

You can add comments to your code as below.


	SELECT
--This is 
--a single-line comment
	employee_id,
	first_name,
	last_name,
	email,
	phone_number
/*This is a multi-line comment.*/
FROM
	hr.employees;
   

It does not matter how you add your comment to the code but it should be clear and precise.

It is highly advisable to use comment methods as per their requirement. In General, Multi-Line comment method is used more frequently. Because in this method, the starting point and the ending point are in our hand. We can terminate comment at any point. See the below code.


	SELECT
	employee_id,first_name,/*Best use of Multi-line comment*/last_name,email,
	phone_number
FROM
	hr.employees;
   

We cannot do so with Single-Line comment method.
We can use these methods in SQL as well as PL-SQL using the same approaches.

If you have any questions/suggestions, please comment below or write me an email.
If you like this blog, do share with your friends and colleagues on your social media.
For more updates join my facebook group and do like my facebook page.

Thank you,
Kapil Kumar
dbgeek.in

Sharing is caring!

You May Also Like..

DUAL TABLE

Oracle_DUAL table

Hey geeks, DUAL table is a very important table available in the Oracle database. It gets created automatically during the […]

Concatenation Operator

Oracle_Concatenation Operator

Hey geeks, This is another chapter of Operators. Concatenation Operator helps to concatenate two or more strings or columns. The […]

Parentheses

Parentheses in SQL

Hey time travellers, Though Parentheses are used pretty much everywhere in SQL but in this blog, we will talk about […]

Leave a Reply

Your email address will not be published. Required fields are marked *