PL SQL Introduction
PL SQL Introduction
PL/SQL Introduction
Last Updated : 11 Nov, 2024
In this article, we’ll cover PL/SQL basics, including its core features,
PL/SQL block structure, and practical examples that demonstrate the
power of PL/SQL. We’ll also explore the differences between SQL and
PL/SQL, how variables and identifiers work, and how the PL/SQL
execution environment operates within Oracle.
Basics of PL/SQL
PL/SQL stands for Procedural Language extensions to the
Structured Query Language (SQL).
PL/SQL is a combination of SQL along with the procedural features
of programming languages.
Oracle uses a PL/SQL engine to process the PL/SQL statements.
PL/SQL includes procedural language elements like conditions and
loops. It allows declaration of constants and variables, procedures
and functions, types and variable of those types and triggers.
Features of PL/SQL
1. PL/SQL is basically a procedural language, which provides the
functionality of decision-making, iteration, and many more features
of procedural programming languages.
2. PL/SQL can execute a number of queries in one block using single
command.
Open In App
3. One can create a PL/SQL unit such as procedures, functions,
packages, triggers, and types, which are stored in the database for
reuse by applications.
4. PL/SQL provides a feature to handle the exception which occurs in
PL/SQL block known as exception handling block.
5. Applications written in PL/SQL are portable to computer hardware or
operating system where Oracle is operational.
6. PL/SQL Offers extensive error checking.
SQL PL/SQL
DECLARE
declaration statements;
BEGIN
executable statements
EXCEPTIONS
exception handling statements
END;
Open In App
Declare section starts with DECLARE keyword in which variables,
constants, records as cursors can be declared which stores data
temporarily. It basically consists definition of PL/SQL identifiers.
This part of the code is optional.
Execution section starts with BEGIN and ends with END
keyword.This is a mandatory section and here the program logic is
written to perform any task like loops and conditional statements. It
supports all DML commands, DDL commands and SQL*PLUS built-in
functions as well.
Exception section starts with EXCEPTION keyword.This section is
optional which contains statements that are executed when a run-
time error occurs. Any exceptions can be handled in this section.
PL/SQL Identifiers
SQL> DECLARE
var1 INTEGER;
var2 REAL;
var3 varchar2(20) ;
BEGIN
null;
END;
/
Open In App
1. Output:
1. Explanation:
SET SERVEROUTPUT ON: It is used to display the buffer used by
the dbms_output.
var1 INTEGER : It is the declaration of variable, named var1 which
is of integer type. There are many other data types that can be
used like float, int, real, smallint, long etc. It also supports
variables used in SQL as well like NUMBER(prec, scale), varchar,
varchar2 etc.
PL/SQL procedure successfully completed.: It is displayed when
the code is compiled and executed successfully.
Slash (/) after END;: The slash (/) tells the SQL*Plus to execute
the block.
Assignment operator (:=) : It is used to assign a value to a
variable.
BEGIN
dbms_output.put_line(var);
END;
/
1. Output:
Open In App
I love GeeksForGeeks
1. Explanation:
dbms_output.put_line : This command is used to direct the
PL/SQL output to a screen.
SQL> DECLARE
BEGIN
null;
END;
/
Open In App
1. Output:
SQL> DECLARE
BEGIN
c := a + b ;
dbms_output.put_line('Sum of '||a||' and '||b||' is =
'||c);
END;
/
The PL/SQL engine resides in the Oracle engine.The Oracle engine can
process not only single SQL statement but also block of many
statements.The call to Oracle engine needs to be made only once to
execute any number of SQL statements if these SQL statements are
bundled inside a PL/SQL block.
Conclusion
PL/SQL is a powerful tool in Oracle for combining SQL with procedural
programming capabilities. With PL/SQL features like error handling,
reusable program units, and support for loops and conditionals,
PL/SQL extends SQL’s data manipulation capabilities and enables
developers to create sophisticated applications within the database. By
understanding SQL vs PL/SQL and the advantages of the PL/SQL
execution environment, developers can unlock the full potential of
Oracle’s PL/SQL language for robust database applications.
Dreaming of M.Tech in IIT? Get AIR under 100 with our GATE 2026
CSE & DA courses! Get flexible weekday/weekend options, live
mentorship, and mock tests. Access exclusive features like All India
Mock Tests, and Doubt Solving—your GATE success starts now!
Advertise with us
PL/SQL Injection
Similar Reads
Introduction to SQLite
SQLite is a highly efficient, serverless, and self-contained SQL database
Open In App
engine that stands out for its simplicity and ease of integration. Designe…
9 min read
Introduction to Couchbase
Couchbase Server is an open-source, distributed, multi-model NoSQL,
JSON document database that is enhanced for interactive applications. …
3 min read
3 min read
5 min read
2 min read
4 min read
6 min read
Open In App
JSON Introduction
JSON (JavaScript Object Notation) is a lightweight, text-based data
format used for representing structured data. It is one of the most widel…
5 min read
8 min read
6 min read
Registered Address:
K 061, Tower K, Gulshan Vivante
Apartment, Sector 137, Noida,
Gautam Buddh Nagar, Uttar Pradesh,
201305
Advertise with us
Open In App