SlideShare a Scribd company logo
1 of 14
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

Similar to Oracle_PLSQL_basic_tutorial_with_workon_Exercises.ppt

Introduction to PL/SQL
Introduction to PL/SQLIntroduction to PL/SQL
Introduction to PL/SQLKailash N
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsOracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsAlex Zaballa
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c  - New Features for Developers and DBAsOracle Database 12c  - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsAlex Zaballa
 
PL/SQL Complete Tutorial. All Topics Covered
PL/SQL Complete Tutorial. All Topics CoveredPL/SQL Complete Tutorial. All Topics Covered
PL/SQL Complete Tutorial. All Topics CoveredDanish Mehraj
 
Exploring plsql new features best practices september 2013
Exploring plsql new features best practices   september 2013Exploring plsql new features best practices   september 2013
Exploring plsql new features best practices september 2013Andrejs Vorobjovs
 
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...Alex Zaballa
 
Lecture 2.3.26_Conditional Control Structure.pptx
Lecture 2.3.26_Conditional Control Structure.pptxLecture 2.3.26_Conditional Control Structure.pptx
Lecture 2.3.26_Conditional Control Structure.pptxShivam481778
 
Cursors, triggers, procedures
Cursors, triggers, proceduresCursors, triggers, procedures
Cursors, triggers, proceduresVaibhav Kathuria
 
L9 l10 server side programming
L9 l10  server side programmingL9 l10  server side programming
L9 l10 server side programmingRushdi Shams
 
10g plsql slide
10g plsql slide10g plsql slide
10g plsql slideTanu_Manu
 
Functions oracle (pl/sql)
Functions oracle (pl/sql)Functions oracle (pl/sql)
Functions oracle (pl/sql)harman kaur
 
Sql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices ISql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices ICarlos Oliveira
 

Similar to Oracle_PLSQL_basic_tutorial_with_workon_Exercises.ppt (20)

Plsql guide 2
Plsql guide 2Plsql guide 2
Plsql guide 2
 
Introduction to PL/SQL
Introduction to PL/SQLIntroduction to PL/SQL
Introduction to PL/SQL
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsOracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAs
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c  - New Features for Developers and DBAsOracle Database 12c  - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAs
 
PL/SQL Complete Tutorial. All Topics Covered
PL/SQL Complete Tutorial. All Topics CoveredPL/SQL Complete Tutorial. All Topics Covered
PL/SQL Complete Tutorial. All Topics Covered
 
Exploring plsql new features best practices september 2013
Exploring plsql new features best practices   september 2013Exploring plsql new features best practices   september 2013
Exploring plsql new features best practices september 2013
 
SQL / PL
SQL / PLSQL / PL
SQL / PL
 
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
 
Lecture 2.3.26_Conditional Control Structure.pptx
Lecture 2.3.26_Conditional Control Structure.pptxLecture 2.3.26_Conditional Control Structure.pptx
Lecture 2.3.26_Conditional Control Structure.pptx
 
Cursors, triggers, procedures
Cursors, triggers, proceduresCursors, triggers, procedures
Cursors, triggers, procedures
 
Chapter8 pl sql
Chapter8 pl sqlChapter8 pl sql
Chapter8 pl sql
 
L9 l10 server side programming
L9 l10  server side programmingL9 l10  server side programming
L9 l10 server side programming
 
10g plsql slide
10g plsql slide10g plsql slide
10g plsql slide
 
Functions oracle (pl/sql)
Functions oracle (pl/sql)Functions oracle (pl/sql)
Functions oracle (pl/sql)
 
PLSQL Tutorial
PLSQL TutorialPLSQL Tutorial
PLSQL Tutorial
 
Dbms 2011
Dbms 2011Dbms 2011
Dbms 2011
 
DBMS 2011
DBMS 2011DBMS 2011
DBMS 2011
 
Sql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices ISql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices I
 
Cursores.ppt
Cursores.pptCursores.ppt
Cursores.ppt
 
plsql les02
 plsql les02 plsql les02
plsql les02
 

Recently uploaded

An introduction to Semiconductor and its types.pptx
An introduction to Semiconductor and its types.pptxAn introduction to Semiconductor and its types.pptx
An introduction to Semiconductor and its types.pptxPurva Nikam
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleAlluxio, Inc.
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...121011101441
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncssuser2ae721
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catcherssdickerson1
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 

Recently uploaded (20)

An introduction to Semiconductor and its types.pptx
An introduction to Semiconductor and its types.pptxAn introduction to Semiconductor and its types.pptx
An introduction to Semiconductor and its types.pptx
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at Scale
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 

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...