This module discussed the tools that you to use to build your queries with PL/SQL. Then you learned about the different variable types that are used within PL/SQL. Further, you enhanced your knowledge of non-PL/SQL bind and host variables. You also reviewed the DBMS_OUTPUT.PUT_LINE
package procedure to display the output to your screen. Finally, you learned the importance of using standard naming conventions while writing your code.
The DBMS_OUTPUT.PUT_LINE procedure is a pre-defined packaged procedure within Oracle PL/SQL's DBMS_OUTPUT package. It plays a fundamental role in the debugging and logging processes by enabling developers to output values, messages, or debug information during PL/SQL program execution.
The syntax for DBMS_OUTPUT.PUT_LINE is as follows:
DBMS_OUTPUT.PUT_LINE (item IN VARCHAR2);
Here, item is a VARCHAR2 parameter that represents the string or variable to be output.
This procedure prints a line of text, followed by a newline character, to the buffer. This output is not visible during normal procedure execution and is only visible once the execution completes. However, it's crucial to remember that the output will not be shown unless the server output is turned on. This is accomplished in SQL*Plus or similar tools by using the SET SERVEROUTPUT ON command.
The primary purpose of the DBMS_OUTPUT.PUT_LINE procedure is to support debugging operations. As PL/SQL lacks a traditional debugging interface, DBMS_OUTPUT.PUT_LINE is used extensively to display the internal processing status, variable values, or execution flow. This helps developers to trace the execution path, locate the errors, and troubleshoot them accordingly.
Moreover, it is also used to produce formatted results for reporting purposes, or to generate logs of PL/SQL program execution.
Keep in mind that DBMS_OUTPUT.PUT_LINE has a limitation on the length of string it can handle. As of my knowledge cut-off in 2021, the maximum string length is 32,767 bytes.
Lastly, while the DBMS_OUTPUT.PUT_LINE is a handy tool, it is advisable not to use it extensively in a production environment as it can impact the performance of PL/SQL programs. Alternative logging or exception handling methods are recommended for handling errors in production code.
In this module you were introduced to the following glossary terms:
- Block: A data block is the smallest unit of data used by a database.
In contrast, at the physical, operating system level, all data is stored in bytes. Each operating system has a block size.
- code walkthrough: Code Walkthrough is a form of peer review in which a programmer leads the review process and the other team members ask questions and spot possible errors against development standards.
- Global: Globals do not respect the boundaries of program interfaces. You can read and write globals without using the parameter list of a module.
- Package: A database program consisting of one or more procedures. A package executes when called using SQL or a programming language interface.
- Procedure: A procedure is a group of PL/SQL statements that you can call by name. A call specification (sometimes called call spec) declares a Java method or a third-generation language (3GL) routine so that it can be called from SQL and PL/SQL.
- Runtime: In computer science, runtime, or execution time is the time during which a program is running a.k.a. (executing).
In the next module, you will learn in detail about datatypes.