PL/SQL stands for Programming Language of SQL. As you are aware, SQL is a non-programming language and achieves it’s objective with single line of code. When folks at ORACLE thought that it was too limiting and in order to make SQL more powerful, they designed PL/SQL.
A SIMPLE PL/SQL CODE BLOCK THAT
DISPLAYS THE WORD HELLO
SQL> set serveroutput on
2 dbms_output.put_line (‘Hello’);
PL/SQL procedure successfully completed.
Here the first statement i.e. serveroutput is set to on in order to enable PL/SQL output. the dbms_output.put_line is a print statement.
A PL/SQL program consists of four parts:
• Header – This is the optional first section of the code block. It is used to
identify the type of code block and its name. The code block types
are: anonymous procedure, named procedure, and function. A
header is only used for the latter two types.
• Declaration – This is an optional section of the code block. It contains the name
of the local objects that will be used in the code block. These
include variables, cursor definitions, and exceptions. This section
begins with the keyword Declare.
• Executable – This is the only mandatory section. It contains the statements that
will be executed. These consist of SQL statements, DML
statements, procedures (PL/SQL code blocks), functions (PL/SQL
code blocks that return a value), and built-in subprograms. This
section starts with the keyword Begin.
• Exception – This is an optional section. It is used to “handle” any errors that
occur during the execution of the statements and commands in the
executable section. This section begins with the keyword
SQL> SET SERVEROUTPUT ON;
2 LOCAL_VARIABLE VARCHAR2(30);
4 SELECT ‘NUMBER OF
5 INTO LOCAL_VARIABLE
6 FROM EMPLOYEE;
9 WHEN OTHERS THEN
NUMBER OF EMPLOYEES 19
PL/SQL PROCEDURE SUCCESSFULLY
There is no header here. It starts with a Declaration. The BEGIN statement marks the start of executable code. EXCEPTION statement defines how errors are to be trapped.
PL/SQL is a very powerful programming language. ORACLE database has thing called stored procedures which are written in PL/SQL. Explore it to the best you can.
Only problem : it’s only compatible with ORACLE.