SlideShare a Scribd company logo
INTRODUCTION TO
PL/SQL
By:
Dheeraj Kashnyal
1
INTRODUCTION TO PL/SQL
• PROCEDURAL LANGUAGE EXTENSION FOR SQL
• ORACLE PROPRIETARY
• 3GL CAPABILITIES
• INTEGRATION OF SQL
• PORTABLE WITHIN ORACLE DATABASES
• CALLABLE FROM ANY CLIENT
2
STRUCTURE OF PL/SQL
3
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;
4
EXERCISE 1 :
5
Let us test our basic SQL knowledge before we
move to actual PL/SQL insights:
1. Create a SQL query to show the current date in
the database.
2. Create a SQL query to show only “UN” from the
word “UNITED” as o/p.
STRUCTURE OF PL/SQL
DECLARE
A NUMBER;
TEXT1 VARCHAR2(20) := ‘HELLO';
TEXT2 VARCHAR2(20);
BEGIN
TEXT2 := ‘WORLD';
DBMS_OUTPUT.PUT_LINE('TEXT1 :'|| TEXT1);
DBMS_OUTPUT.PUT_LINE('TEXT2 :' || TEXT2);
DBMS_OUTPUT.PUT_LINE(TEXT1 ||' ' || TEXT2);
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} “
6
DEBUGING
• SHOW ERROR;
• DBMS_OUTPUT.PUT_LINE(‘ .. ‘);
• SET SERVEROUTPUT ON;
• EXCEPTION BLOCKS;
7
EXERCISE 2:
• CREATE A PL/SQL BLOCK TO SHOW YOUR NAME ,DOJ &
EMP_ID IN THE O/P .
• CREATE A PL/SQL BLOCK TO CALCULATE YOUR EXPERIENCE
IN MONTHS.
8
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 9
PL/SQL CONTROL STRUCTURE
10
PL/SQL has several control structures
which include:
• 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;
11
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;
12
PL/SQL CONTROL STRUCTURE –
UPCOMING SESSIONS
• 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;
13
THANK YOU
14
Stay tuned for more
interactive learning
sessions...

More Related Content

PPT
lec_pl_sql.ppthjiji2kkwkwkwjwjwjwjsjsjwjwj
PPT
pl_sql.ppt
PPTX
ORACLE PL/SQL
PPTX
4. plsql
PPTX
PLSQL Tutorial
PDF
PLSQL tutorial...
PDF
plsql_tutorial.pdf
PPT
Introduction to PLSQL.PPT
lec_pl_sql.ppthjiji2kkwkwkwjwjwjwjsjsjwjwj
pl_sql.ppt
ORACLE PL/SQL
4. plsql
PLSQL Tutorial
PLSQL tutorial...
plsql_tutorial.pdf
Introduction to PLSQL.PPT

Similar to Oracle_PLSQL_basic_tutorial_with_workon_Exercises.ppt (20)

PDF
PL/SQL Complete Tutorial. All Topics Covered
PDF
B.Sc. II (IV Sem) RDBMS & PL/SQL Unit-5 PL/SQL, Cursor and Trigger
PDF
Dbms 2011
PPT
Ppt on plssql study aboutnsmsmskskwkwkwkwk
PDF
Procedural Language/Structured Query Language
PPTX
PL/SQL is a block structured language that enables developers to combine the ...
PDF
RDBMS - UNIT 4.pdf,UNIT THREE AND UNIT FIVE
PPTX
PLSQL.pptx
PDF
PL_SQL
PDF
Lecture Notes Unit5 chapter 15 PL/SQL Programming
PPTX
Ch as pbdasdadssadsadsadasdasdasdas fdt .pptx
PPTX
PL_SQL, Trigger, Cursor, Stored procedure ,function
DOC
Chapter 1
PPTX
PLSql.pptx
PPTX
Pl sql Prograaming of Database management system
PPTX
pl/sql online Training|sql online Training | iTeknowledge
PDF
PDF
PDF
PL/SQL Complete Tutorial. All Topics Covered
B.Sc. II (IV Sem) RDBMS & PL/SQL Unit-5 PL/SQL, Cursor and Trigger
Dbms 2011
Ppt on plssql study aboutnsmsmskskwkwkwkwk
Procedural Language/Structured Query Language
PL/SQL is a block structured language that enables developers to combine the ...
RDBMS - UNIT 4.pdf,UNIT THREE AND UNIT FIVE
PLSQL.pptx
PL_SQL
Lecture Notes Unit5 chapter 15 PL/SQL Programming
Ch as pbdasdadssadsadsadasdasdasdas fdt .pptx
PL_SQL, Trigger, Cursor, Stored procedure ,function
Chapter 1
PLSql.pptx
Pl sql Prograaming of Database management system
pl/sql online Training|sql online Training | iTeknowledge
Ad

Recently uploaded (20)

PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
Internet of Things (IOT) - A guide to understanding
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
additive manufacturing of ss316l using mig welding
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPT
Mechanical Engineering MATERIALS Selection
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
Lecture Notes Electrical Wiring System Components
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Internet of Things (IOT) - A guide to understanding
Model Code of Practice - Construction Work - 21102022 .pdf
CH1 Production IntroductoryConcepts.pptx
additive manufacturing of ss316l using mig welding
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
Embodied AI: Ushering in the Next Era of Intelligent Systems
Mechanical Engineering MATERIALS Selection
R24 SURVEYING LAB MANUAL for civil enggi
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Lecture Notes Electrical Wiring System Components
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Foundation to blockchain - A guide to Blockchain Tech
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Ad

Oracle_PLSQL_basic_tutorial_with_workon_Exercises.ppt

  • 2. INTRODUCTION TO PL/SQL • PROCEDURAL LANGUAGE EXTENSION FOR SQL • ORACLE PROPRIETARY • 3GL CAPABILITIES • INTEGRATION OF SQL • PORTABLE WITHIN ORACLE DATABASES • CALLABLE FROM ANY CLIENT 2
  • 3. STRUCTURE OF PL/SQL 3 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
  • 4. STRUCTURE OF PL/SQL HEADER TYPE AND NAME OF BLOCK DECLARE VARIABLES; CONSTANTS; CURSORS; BEGIN PL/SQL AND SQL STATEMENTS EXCEPTION EXCEPTION HANDLERS END; 4
  • 5. EXERCISE 1 : 5 Let us test our basic SQL knowledge before we move to actual PL/SQL insights: 1. Create a SQL query to show the current date in the database. 2. Create a SQL query to show only “UN” from the word “UNITED” as o/p.
  • 6. STRUCTURE OF PL/SQL DECLARE A NUMBER; TEXT1 VARCHAR2(20) := ‘HELLO'; TEXT2 VARCHAR2(20); BEGIN TEXT2 := ‘WORLD'; DBMS_OUTPUT.PUT_LINE('TEXT1 :'|| TEXT1); DBMS_OUTPUT.PUT_LINE('TEXT2 :' || TEXT2); DBMS_OUTPUT.PUT_LINE(TEXT1 ||' ' || TEXT2); 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} “ 6
  • 7. DEBUGING • SHOW ERROR; • DBMS_OUTPUT.PUT_LINE(‘ .. ‘); • SET SERVEROUTPUT ON; • EXCEPTION BLOCKS; 7
  • 8. EXERCISE 2: • CREATE A PL/SQL BLOCK TO SHOW YOUR NAME ,DOJ & EMP_ID IN THE O/P . • CREATE A PL/SQL BLOCK TO CALCULATE YOUR EXPERIENCE IN MONTHS. 8
  • 9. 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 9
  • 10. PL/SQL CONTROL STRUCTURE 10 PL/SQL has several control structures which include: • 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.
  • 11. PL/SQL CONTROL STRUCTURE • CONDITIONAL CONTROLS IF....THEN....END IF; IF....THEN...ELSE....END IF; IF....THEN...ELSIF....THEN....ELSE....END IF; 11
  • 12. 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; 12
  • 13. PL/SQL CONTROL STRUCTURE – UPCOMING SESSIONS • 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; 13
  • 14. THANK YOU 14 Stay tuned for more interactive learning sessions...