Comments in PL/SQL
The comments are a piece of code that exist to improve readability. The comments are written in the program, either as a single line or multiple lines of documentation. A single line or multiline comments are separated from the rest of the program through delimiters, so the PL / SQL engine will ignore them.Comments are of Two types.Inline comments and multi line comments.
Inline comments
Inline Comments begins with a Double hyphen(The single line comment delimiter, ). The comment starts after the hyphen, and includes a single line of text only. If a second line is needed, the following should also include the delimiter at the beginning.
The following example shows use of single line comments
DECLARE
v_emp_name VARCHAR2(50);
BEGIN
– Retrieve the name of a employee into a local variable from employee database
SELECT emp_name
INTO v_emp_name
FROM employees
WHERE emp_id = ’9895678′;
–Prints the employee name to the screen
DBMS_OUTPUT.PUT_LINE(‘The Employee name for employee id 9895678 is: ‘
||v_emp_id);
EXCEPTION
–print exception if any
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE (SQLERRM);
END;
/
Multi Line Comments
anonymous comments of several lines of multi line comment use ‘/*; as a starting comment delimiter and * / ;as a ending comment delimiter. We can use multiline Comments on several lines or paragraphs. They are useful for headings or notes, including version control in the PL / SQL directly. The following example illustrates the multi-line comments in an anonymous block:
/*
Author : MARY PETER
Description : Sample Program to find employee name
*/
DECLARE
v_emp_name VARCHAR2(50);
BEGIN
– Retrieve the name of a employee into a local variable from employee database
SELECT emp_name
INTO v_emp_name
FROM employees
WHERE emp_id = ’9895678′;
–Prints the employee name to the screen
DBMS_OUTPUT.PUT_LINE(‘The Employee name for employee id 9895678 is: ‘
||v_emp_id);
/*
This code will not be executed
UPDATE emp_salary =emp_salary *.23
WHERE emp_name=v_emp_id
*/
EXCEPTION
–print exception if any
WHEN OTHERS
THEN DBMS_OUTPUT.PUT_LINE (SQLERRM);
END;
/
Multiline comments can be used for
■ Header information For PL/SQL scripts
■ Header information For PL/SQL Objects
■ To comment blocks of code. This is useful for the trial or effectively eliminate the code, but allowing for future use of the code
comments that go beyond simple lines
■ For comments that extend beyond single lines