SlideShare a Scribd company logo
Introduction to PL/SQL
• PL/SQL is a combination of SQL along
with the procedural features of
programming languages. It was developed
by Oracle Corporation in the early 90's to
enhance the capabilities of SQL. PL/SQL
is one of three key programming
languages embedded in the Oracle
Database, along with SQL itself and Java.
This tutorial will give you great
understanding on PL/SQL to proceed with
Oracle database and other advanced
RDBMS concepts.
• PL/SQL is not a standalone programming
language; it is a tool within the Oracle
programming environment. SQL* Plus is
an interactive tool that allows you to type
SQL and PL/SQL statements at the
command prompt. These commands are
then sent to the database for processing.
Once the statements are processed, the
results are sent back and displayed on
screen.
• To run PL/SQL programs, you should
have the Oracle RDBMS Server installed
in your machine. This will take care of the
execution of the SQL commands. The
most recent version of Oracle RDBMS is
11g. You can download a trial version of
Oracle 11g from the following link −
• Download Oracle 11g Express Edition
• In this chapter, we will discuss the Basic
Syntax of PL/SQL which is a block-
structured language; this means that the
PL/SQL programs are divided and written
in logical blocks of code. Each block
consists of three sub-parts −
S.No Sections & Description
1
Declarations
This section starts with the
keyword DECLARE. It is
an optional section and
defines all variables,
cursors, subprograms, and
other elements to be used
in the program.
2
Executable Commands
This section is enclosed
between the
keywords BEGIN and END
and it is a mandatory
section. It consists of the
executable PL/SQL
statements of the program.
It should have at least one
executable line of code,
which may be just a NULL
command to indicate that
nothing should be
executed.
3
Exception Handling
This section starts with the
keyword EXCEPTION.
This optional section
contains exception(s) that
handle errors in the
program.
• Every PL/SQL statement ends with a
semicolon (;). PL/SQL blocks can be
nested within other PL/SQL blocks
using BEGIN and END. Following is the
basic structure of a PL/SQL block −
• DECLARE <declarations section> BEGIN
<executable command(s)> EXCEPTION
<exception handling> END;
Introduction to PL/SQL
• Procedural Language extension for SQL
• Oracle Proprietary
• 3GL Capabilities
• Integration of SQL
• Portable within Oracle data bases
• Callable from any client
Structure of PL/SQL
• PL/SQL is Block Structured
A block is the basic unit from which all PL/SQL
programs are built. A block can be named
(functions and procedures) or anonymous
• Sections of block
1- Header Section
2- Declaration Section
3- Executable Section
4- Exception Section
Structure of PL/SQL
HEADER
Type and Name of block
DECLARE
Variables; Constants; Cursors;
BEGIN
PL/SQL and SQL Statements
EXCEPTION
Exception handlers
END;
Structure of PL/SQL
DECLARE
a number;
text1 varchar2(20);
text2 varchar2(20) := “HI”;
BEGIN
---------- ---------- ----------
END;
Important Data Types in PL/SQL include
NUMBER, INTEGER, CHAR, VARCHAR2, DATE
etc
to_date(‘02-05-2007','dd-mm-yyyy') { Converts
String to Date}
Structure of PL/SQL
• Data Types for specific columns
Variable_name Table_name.Column_name%type;
This syntax defines a variable of the type of the
referenced column on the referenced table
PL/SQL Control Structure
• PL/SQL has a number of control structures
which includes:
• Conditional controls
• Iterative or loop controls.
• Exception or error controls
• It is these controls, used singly or together, that
allow the PL/SQL developer to direct the flow of
execution through the program.
PL/SQL Control Structure
• Conditional Controls
IF....THEN....END IF;
IF....THEN...ELSE....END IF;
IF....THEN...ELSIF....THEN....ELSE....END IF;
PL/SQL Control Structure
• LOOP
...SQL Statements...
EXIT;
END LOOP;
• WHILE loops
• WHILE condition LOOP
...SQL Statements...
END LOOP;
• FOR loops
• FOR <variable(numeric)> IN [REVERSE]
<lowerbound>..<upperbound> LOOP .... ..... END LOOP;
PL/SQL Control Structure
• Cursor
DECLARE
name varchar2(20);
Cursor c1 is
select t.name
from table t
where date is not null;
BEGIN
OPEN c1;
LOOP
FETCH c1 into name;
exit when c1%NOTFOUND;
END LOOP;
CLOSE c1;
END;
Debuging
• show error
• DBMS_OUTPUT.PUT_LINE(‘ .. ‘);
Execution
• How to execute a function in PL/SQL?
Var issue_flag number;
exec :issue_flag:=fun_name(arg1,arg2,. . . .);
PRINT :issue_flag;
• How to execute a procedure in PL/SQL?
Exec procedure_name(arg1,arg2,. . . .);
THANK YOU
References
[1] http://www.csee.umbc.edu/help/oracle8/server.815/a67842/01_oview.htm#740
[2] http://en.wikipedia.org/wiki/PL/SQL
[3] http://www.skillbuilders.com/Tutorials-V2/ora9i_Intro_to_PLSQL/ora9i_Intro_to_PLSQL.cfm

More Related Content

PPTX
PL/SQL is a block structured language that enables developers to combine the ...
PDF
PL/SQL Complete Tutorial. All Topics Covered
PDF
Pl sql-ch1
PDF
chapter 1.pdfbbbbbbbbbbbbbbbbbbbbbbbbbb
PDF
rdbms.pdf plsql database system notes for students to study
PPT
Oracle_PLSQL_basic_tutorial_with_workon_Exercises.ppt
PPTX
Pl sql chapter 1
PPT
lec_pl_sql.ppthjiji2kkwkwkwjwjwjwjsjsjwjwj
PL/SQL is a block structured language that enables developers to combine the ...
PL/SQL Complete Tutorial. All Topics Covered
Pl sql-ch1
chapter 1.pdfbbbbbbbbbbbbbbbbbbbbbbbbbb
rdbms.pdf plsql database system notes for students to study
Oracle_PLSQL_basic_tutorial_with_workon_Exercises.ppt
Pl sql chapter 1
lec_pl_sql.ppthjiji2kkwkwkwjwjwjwjsjsjwjwj

Similar to pl_sql.ppt (20)

PPT
Pl sql
PDF
PROCEDURAL LANGUAGE/ STRUCTURED QUERY LANGUAGE.pdf
PPT
Chapter8 pl sql
PDF
Oracle PL/SQL online training | PL/SQL online Training
DOC
Chapter 1
PPTX
Pl sql Prograaming of Database management system
PDF
PDF
PDF
PPTX
PLSql.pptx
PPT
Introduction to PLSQL.PPT
PDF
RDBMS - UNIT 4.pdf,UNIT THREE AND UNIT FIVE
PDF
Database management system chapter5
PPTX
PL SQL.pptx in computer language in database
DOCX
What does PL_SQL stand for and what is the functioning of PL_SQL.docx
PPTX
Ch as pbdasdadssadsadsadasdasdasdas fdt .pptx
PDF
PL/SQL for Beginners - PL/SQL Tutorial 1
PPTX
Introduction to PL/SQL
PPT
SQL / PL
Pl sql
PROCEDURAL LANGUAGE/ STRUCTURED QUERY LANGUAGE.pdf
Chapter8 pl sql
Oracle PL/SQL online training | PL/SQL online Training
Chapter 1
Pl sql Prograaming of Database management system
PLSql.pptx
Introduction to PLSQL.PPT
RDBMS - UNIT 4.pdf,UNIT THREE AND UNIT FIVE
Database management system chapter5
PL SQL.pptx in computer language in database
What does PL_SQL stand for and what is the functioning of PL_SQL.docx
Ch as pbdasdadssadsadsadasdasdasdas fdt .pptx
PL/SQL for Beginners - PL/SQL Tutorial 1
Introduction to PL/SQL
SQL / PL

Recently uploaded (20)

PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
DOCX
573137875-Attendance-Management-System-original
PPTX
Construction Project Organization Group 2.pptx
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PDF
III.4.1.2_The_Space_Environment.p pdffdf
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PPT
Mechanical Engineering MATERIALS Selection
PPTX
Fundamentals of safety and accident prevention -final (1).pptx
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPT
introduction to datamining and warehousing
PDF
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PDF
Categorization of Factors Affecting Classification Algorithms Selection
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
Sustainable Sites - Green Building Construction
Foundation to blockchain - A guide to Blockchain Tech
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
573137875-Attendance-Management-System-original
Construction Project Organization Group 2.pptx
R24 SURVEYING LAB MANUAL for civil enggi
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
III.4.1.2_The_Space_Environment.p pdffdf
UNIT-1 - COAL BASED THERMAL POWER PLANTS
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
Mechanical Engineering MATERIALS Selection
Fundamentals of safety and accident prevention -final (1).pptx
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
introduction to datamining and warehousing
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Categorization of Factors Affecting Classification Algorithms Selection
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Sustainable Sites - Green Building Construction

pl_sql.ppt

  • 2. • PL/SQL is a combination of SQL along with the procedural features of programming languages. It was developed by Oracle Corporation in the early 90's to enhance the capabilities of SQL. PL/SQL is one of three key programming languages embedded in the Oracle Database, along with SQL itself and Java. This tutorial will give you great understanding on PL/SQL to proceed with Oracle database and other advanced RDBMS concepts.
  • 3. • PL/SQL is not a standalone programming language; it is a tool within the Oracle programming environment. SQL* Plus is an interactive tool that allows you to type SQL and PL/SQL statements at the command prompt. These commands are then sent to the database for processing. Once the statements are processed, the results are sent back and displayed on screen.
  • 4. • To run PL/SQL programs, you should have the Oracle RDBMS Server installed in your machine. This will take care of the execution of the SQL commands. The most recent version of Oracle RDBMS is 11g. You can download a trial version of Oracle 11g from the following link − • Download Oracle 11g Express Edition
  • 5. • In this chapter, we will discuss the Basic Syntax of PL/SQL which is a block- structured language; this means that the PL/SQL programs are divided and written in logical blocks of code. Each block consists of three sub-parts −
  • 6. S.No Sections & Description 1 Declarations This section starts with the keyword DECLARE. It is an optional section and defines all variables, cursors, subprograms, and other elements to be used in the program. 2 Executable Commands This section is enclosed between the keywords BEGIN and END and it is a mandatory section. It consists of the executable PL/SQL statements of the program. It should have at least one executable line of code, which may be just a NULL command to indicate that nothing should be executed. 3 Exception Handling This section starts with the keyword EXCEPTION. This optional section contains exception(s) that handle errors in the program.
  • 7. • Every PL/SQL statement ends with a semicolon (;). PL/SQL blocks can be nested within other PL/SQL blocks using BEGIN and END. Following is the basic structure of a PL/SQL block −
  • 8. • DECLARE <declarations section> BEGIN <executable command(s)> EXCEPTION <exception handling> END;
  • 9. Introduction to PL/SQL • Procedural Language extension for SQL • Oracle Proprietary • 3GL Capabilities • Integration of SQL • Portable within Oracle data bases • Callable from any client
  • 10. Structure of PL/SQL • PL/SQL is Block Structured A block is the basic unit from which all PL/SQL programs are built. A block can be named (functions and procedures) or anonymous • Sections of block 1- Header Section 2- Declaration Section 3- Executable Section 4- Exception Section
  • 11. Structure of PL/SQL HEADER Type and Name of block DECLARE Variables; Constants; Cursors; BEGIN PL/SQL and SQL Statements EXCEPTION Exception handlers END;
  • 12. Structure of PL/SQL DECLARE a number; text1 varchar2(20); text2 varchar2(20) := “HI”; BEGIN ---------- ---------- ---------- END; Important Data Types in PL/SQL include NUMBER, INTEGER, CHAR, VARCHAR2, DATE etc to_date(‘02-05-2007','dd-mm-yyyy') { Converts String to Date}
  • 13. Structure of PL/SQL • Data Types for specific columns Variable_name Table_name.Column_name%type; This syntax defines a variable of the type of the referenced column on the referenced table
  • 14. PL/SQL Control Structure • PL/SQL has a number of control structures which includes: • Conditional controls • Iterative or loop controls. • Exception or error controls • It is these controls, used singly or together, that allow the PL/SQL developer to direct the flow of execution through the program.
  • 15. PL/SQL Control Structure • Conditional Controls IF....THEN....END IF; IF....THEN...ELSE....END IF; IF....THEN...ELSIF....THEN....ELSE....END IF;
  • 16. PL/SQL Control Structure • LOOP ...SQL Statements... EXIT; END LOOP; • WHILE loops • WHILE condition LOOP ...SQL Statements... END LOOP; • FOR loops • FOR <variable(numeric)> IN [REVERSE] <lowerbound>..<upperbound> LOOP .... ..... END LOOP;
  • 17. PL/SQL Control Structure • Cursor DECLARE name varchar2(20); Cursor c1 is select t.name from table t where date is not null; BEGIN OPEN c1; LOOP FETCH c1 into name; exit when c1%NOTFOUND; END LOOP; CLOSE c1; END;
  • 18. Debuging • show error • DBMS_OUTPUT.PUT_LINE(‘ .. ‘);
  • 19. Execution • How to execute a function in PL/SQL? Var issue_flag number; exec :issue_flag:=fun_name(arg1,arg2,. . . .); PRINT :issue_flag; • How to execute a procedure in PL/SQL? Exec procedure_name(arg1,arg2,. . . .);