Comments - (Oracle Misc)
Comments are used in Oracle PL/SQL code to explain the purpose or functionality of parts of the code. They are ignored by the compiler, and do not affect the execution of the program.
Syntax
Comments in PL/SQL code can be written in two ways:
- Single line comments: start with two hyphens (--), and continue until the end of the line.
- Multi-line comments: start with slash-asterisk (/) and end with asterisk-slash (/), and can span multiple lines.
-- This is a single line comment
/*
This is a
multi-line
comment
*/
Example
DECLARE
-- declare variables
v_salary NUMBER(8,2);
BEGIN
-- assign a value to the variable
v_salary := 5000.00;
/* print the value
of the variable */
dbms_output.put_line('Salary: ' || v_salary);
END;
Output
Salary: 5000.00
Explanation
In the above example, we have declared a variable called v_salary
and assigned it a value of 5000. We have then used a comment to explain what the variable represents. We have also used a comment to explain what the subsequent code does, which is to print the value of the variable.
Use
Comments are used in PL/SQL code to improve code readability and maintainability. They help explain what the code does, how it does it, and why it does it. This makes it easier for other developers to understand and modify the code in the future.
Important Points
- Comments in PL/SQL can be written using single-line or multi-line syntax.
- Comments are ignored by the compiler and do not affect program execution.
- Comments improve code readability and maintainability.
- Use comments to explain what the code does, how it does it, and why it does it.
Summary
In summary, comments in Oracle PL/SQL are used to explain the purpose or functionality of parts of the code. They improve code readability and maintainability, and are ignored by the compiler. Use comments to explain what the code does, how it does it, and why it does it.