-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Advanced Oracle PL/SQL Developer's Guide (Second Edition)
By :

PL/SQL stands for Procedural Language-Structured Query Language(PL/SQL). It is part of the Oracle Database product, which means no separate installation is required. It is commonly used to translate business logic in the database and expose the program interface layer to the application. While SQL is purely a data access language that directly interacts with the database, PL/SQL is a programming language in which multiple SQLs and procedural statements can be grouped in a program unit. PL/SQL code is portable between Oracle Databases (subject to limitations imposed by versions). The built-in database optimizer refactors the code to improve the execution performance.
The advantages of PL/SQL as a language are as follows:
Although it is not used to build user interfaces, it provides the opportunity to build robust, secure, and portable interface layers, which can be exposed to a high-level programming language. Some of the key faculties of PL/SQL (PL/SQL accomplishments) are listed here:
A well-written PL/SQL program should be able to answer the following fundamental questions:
Well, there are multiple tips and techniques to standardize PL/SQL coding practices. But before we drill down to the programming skills, let us familiarize ourselves with the structure of a PL/SQL program. A PL/SQL program can be broken down into four sections. Each section carries a specific objective and must exist in the same sequence in a program. Let us have a brief look at the sections:
DECLARE
keyword indicates the beginning of the declaration section. The section can be skipped if the PL/SQL program uses no variables.BEGIN
and END
keywords indicate the beginning and end of the program body. It must contain at least one executable statement. During block execution, these statements are parsed and sequentially executed by the PL/SQL engine.EXCEPTION
keyword indicates the start of the exception section.The following block diagram shows the structure of a PL/SQL block:
A PL/SQL block is the elementary unit of a program that groups a set of procedural statements. Based on the sections included in a PL/SQL program unit, we can classify a program under following categories:
DECLARE
-BEGIN
-END
skeleton. It can either be run for current execution as standalone block or embedded locally within a PL/SQL program unit. An anonymous block cannot be stored in the database.So, let's get started with our first anonymous PL/SQL block. The block declares a string and displays it on screen. Note that each line in the program ends with a semi-colon and the block ends with a slash (/
) for code execution.
/*Enable the Serveroutput to display block messages*/ SET SERVEROUTPUT ON
The SERVEROUTPUT
parameter is a SQL*Plus variable that enables the printing of DBMS_OUTPUT messages from a PL/SQL block.
/*Start the PL/SQL block*/ DECLARE /*Declare a local variable and initialize with a default value*/ L_STR VARCHAR2(50) := 'I am new to PL/SQL'; BEGIN /*Print the result*/ DBMS_OUTPUT.PUT_LINE('I Said - '||L_STR); END; / I Said - I am new to PL/SQL PL/SQL procedure successfully completed.
Change the font size
Change margin width
Change background colour