![]() |
||
Lesson 5
Objective
|
Adding comments
Add comments to a PL/SQL block. |
|
|
Ask any IT consultant what differentiates a good programmer from a bad one, and
they will answer that good programmers always comment their code. Adding comments to code promotes readability and aids
in logic comprehension and code maintenance.
Multiline comments
Comments are strictly informational and do not enforce any conditions or behavioral logic or data. In fact, the Oracle compiler ignores all comments. Comments are used to describe the purpose and use of each code segment. PL/SQL supports two comment styles. Single-line comments Single-line comments begin with a double hyphen (--) anywhere on a line and can extend to the end of line. -- This is an example of a comment Multiline comments begin with /* and end with /.
They can span multiple lines. Multiline comments can be used to comment out whole sections of code.
/* This is an example of a comment that spans more than one line. */
Another great way to enhance clarity and readability of your code is to indent each subsequent level within a hanging indent level.
Here is a good example of a well-documented PL/SQL block.
Click the View Code link below .
In the next lesson, we will discuss explicit versus implicit datatype conversions.
View Code Now that you have learned about PL/SQL blocks as well as literals, identifiers, and comments, lets use an instructional simulation to build a nested PL/SQL block. The following simulation demonstrates the creation of a PL/SQL block that declares a variable as a number. This variable is assigned the value 42. This block includes a nested block that converts this number as a string and displays the values using DBMS_OUTPUT.PUT_LINE.
Adding Comments |
||
|
|
||
