SlideShare a Scribd company logo
www.srinimf.com
ï‚Ą Originally modeled after ADA
 Created for Dept. of Defense
ï‚Ą Allows expanded functionality of database
applications
ï‚Ą Continues to improve with each new
database release
WWW.SRINIMF.COM 2
ï‚Ą Features
 Tight integration with SQL
â–Ș Supports data types, functions, pseudo-columns, etc.
 Increased performance
â–Ș A block of statements sent as a single statement
 Increased productivity
â–Ș Same techniques can be used with most Oracle products
 Portability
â–Ș Works on any Oracle platform
 Tighter security
â–Ș Users may access database objects without granted privileges
WWW.SRINIMF.COM 3
ï‚Ą Declaration section (optional)
 Any needed variables declared here
ï‚Ą Executable or begin section
 Program code such as statements to retrieve or
manipulate data in a table
ï‚Ą Exception section (optional)
 Error traps can catch situations which might
ordinarily crash the program
WWW.SRINIMF.COM 4
WWW.SRINIMF.COM 5
ï‚Ą Variables are local to the code block
ï‚Ą Names can be up to 30 characters long and must
begin with a character
ï‚Ą Declaration is like that in a table
 Name then data type the semi-colon
 Can be initialized using := operator in the declaration
 Can be changed with := in the begin section
 Can use constraints
ï‚Ą Variables can be composite or collection types
 Multiple values of different or same type
WWW.SRINIMF.COM 6
 CHAR ( max_length )
 VARCHAR2 ( max_length )
 NUMBER ( precision, scale )
 BINARY_INTEGER – more efficient than number
 RAW ( max_length )
 DATE
 BOOLEAN (true, false, null)
 Also LONG, LONG RAW and LOB types but the capacity is
usually less in PL/SQL than SQL
WWW.SRINIMF.COM 7
ï‚Ą NOT NULL
 Can not be empty
ï‚Ą CONSTANT
 Can not be changed
WWW.SRINIMF.COM 8
Age number;
Last char ( 10 );
DVal Date := Sysdate;
SID number not null;
Adjust constant number := 1;
CanLoop boolean := true
WWW.SRINIMF.COM 9
ï‚Ą INVALID_NUMBER (ORA-01722)
 Attempted to store non-numeric data in a variable with
a numeric data type
ï‚Ą NO_DATA_FOUND (ORA-01403)
 Query resulted in no rows being found
ï‚Ą NOT_LOGGED_ON (ORA-01012)
 Not currently connected to an Oracle database
ï‚Ą TOO_MANY_ROWS (ORA-01422)
 A SELECT INTO statement returned more than one row
WWW.SRINIMF.COM 10
ï‚Ą DUP_VALUE_ON_INDEX (ORA-00001)
 Value inserted for a primary key is not unique
ï‚Ą VALUE_ERROR (ORA-06502)
 The value being placed in a variable is the wrong length
or data type
ï‚Ą ZERO_DIVIDE (ORA-01476)
 An attempt was made to divide a number by zero
WWW.SRINIMF.COM 11
WWW.SRINIMF.COM 12
ï‚Ą IF-THEN
ï‚Ą IF-THEN-ELSE
ï‚Ą IF-THEN-ELSIF
 An alternative to nested IF-THEN_ELSE
WWW.SRINIMF.COM 13
WWW.SRINIMF.COM 14
WWW.SRINIMF.COM 15
WWW.SRINIMF.COM 16
WWW.SRINIMF.COM 17
ï‚Ą The first line is called the Procedure
Specification
ï‚Ą The remainder is the Procedure Body
ï‚Ą A procedure is compiled and loaded in the
database as an object
ï‚Ą Procedures can have parameters passed to
them
WWW.SRINIMF.COM 18
ï‚Ą Run a procedure with the PL/SQL EXECUTE
command
ï‚Ą Parameters are enclosed in parentheses
WWW.SRINIMF.COM 19
ï‚Ą Like a procedure except they return a single
value
WWW.SRINIMF.COM 20
ï‚Ą Associated with a particular table
ï‚Ą Automatically executed when a particular
event occurs
 Insert
 Update
 Delete
 Others
WWW.SRINIMF.COM 21
ï‚Ą Procedures are explicitly executed by a user
or application
ï‚Ą Triggers are implicitly executed (fired) when
the triggering event occurs
ï‚Ą Triggers should not be used as a lazy way to
invoke a procedure as they are fired every
time the event occurs
WWW.SRINIMF.COM 22
WWW.SRINIMF.COM 23
ï‚Ą The trigger specification names the trigger
and indicates when it will fire
ï‚Ą The trigger body contains the PL/SQL code
to accomplish whatever task(s) need to be
performed
WWW.SRINIMF.COM 24
WWW.SRINIMF.COM 25
ï‚Ą A triggers timing has to be specified first
 Before (most common)
â–Ș Trigger should be fired before the operation
â–Ș i.e. before an insert
 After
â–Ș Trigger should be fired after the operation
â–Ș i.e. after a delete is performed
WWW.SRINIMF.COM 26
ï‚Ą Three types of events are available
 DML events
 DDL events
 Database events
WWW.SRINIMF.COM 27
ï‚Ą Changes to data in a table
 Insert
 Update
 Delete
WWW.SRINIMF.COM 28
ï‚Ą Changes to the definition of objects
 Tables
 Indexes
 Procedures
 Functions
 Others
â–Ș Include CREATE, ALTER and DROP statements on these
objects
WWW.SRINIMF.COM 29
ï‚Ą Server Errors
ï‚Ą Users Log On or Off
ï‚Ą Database Started or Stopped
WWW.SRINIMF.COM 30
ï‚Ą Can specify one or more events in the
specification
 i.e. INSERT OR UPDATE OR DELETE
ï‚Ą Can specify one or more columns to be
associated with a type of event
 i.e. BEFORE UPDATE OF SID OR SNAME
WWW.SRINIMF.COM 31
ï‚Ą The next item in the trigger is the name of
the table to be affected
WWW.SRINIMF.COM 32
ï‚Ą Two levels for Triggers
 Row-level trigger
â–Ș Requires FOR EACH ROW clause
â–Ș If operation affects multiple rows, trigger fires once for each row
affected
 Statement-level trigger
 DML triggers should be row-level
 DDL and Database triggers should not be row-
level
WWW.SRINIMF.COM 33
WWW.SRINIMF.COM 34
ï‚Ą Conditions Available So Multiple Operations
Can Be Dealt With In Same Trigger
 Inserting, Updating, Deleting
ï‚Ą Column Prefixes Allow Identification Of Value
Changes
 New, Old
WWW.SRINIMF.COM 35
ï‚Ą EXCEPTION Data Type Allows Custom
Exceptions
ï‚Ą RAISE Allows An Exception To Be Manually
Occur
ï‚Ą RAISE_APPLICATION_ERROR Allows
Termination Using A Custom Error Message
 Must Be Between -20000 and -20999
 Message Can Be Up to 512 Bytes
WWW.SRINIMF.COM 36
ï‚Ą Cursors Hold Result of an SQL Statement
ï‚Ą Two Types of Cursors in PL/SQL
 Implicit – Automatically Created When a Query or
Manipulation is for a Single Row
 Explicit – Must Be Declared by the User
â–Ș Creates a Unit of Storage Called a Result Set
WWW.SRINIMF.COM 37
Result Set
MIS380 DATABASE DESIGN 4
MIS202 INFORMATION SYSTEMS 3 <Cursor
MIS485 MANAGING TECHNOLOGY4
MIS480 ADVANCED DATABASE 4
WWW.SRINIMF.COM 38
ï‚Ą Declaring an Explicit Cursor
CURSOR CursorName IS SelectStatement;
ï‚Ą Opening an Explicit Cursor
OPEN CursorName;
ï‚Ą Accessing Rows from an Explicit Cursor
FETCH CursorName INTO RowVariables;
WWW.SRINIMF.COM 39
ï‚Ą Declaring Variables of the Proper Type with
%TYPE
VarName TableName.FieldName%TYPE;
ï‚Ą Declaring Variables to Hold An Entire Row
VarName CursorName%ROWTYPE;
ï‚Ą Releasing the Storage Area Used by an
Explicit Cursor
CLOSE CursorName;
WWW.SRINIMF.COM 40
ï‚Ą LOOP 
 EXIT 
 END LOOP
 EXIT with an If Avoids Infinite Loop
ï‚Ą LOOP 
 EXIT WHEN 
 END LOOP
 Do Not Need An If to Control EXIT
ï‚Ą WHILE 
 LOOP 
 END LOOP
 Eliminates Need for EXIT
ï‚Ą FOR 
 IN 
 END LOOP
 Eliminates Need for Initialization of Counter
WWW.SRINIMF.COM 41
ï‚Ą Need a Way to Fetch Repetitively
ï‚Ą Need a Way to Determine How Many Rows
to Process With a Cursor
 Cursor Attributes
â–Ș CursorName%ROWCOUNT – Number of Rows in a
Result Set
â–Ș CursorName%FOUND – True if a Fetch Returns a Row
â–Ș CursorName%NOTFOUND – True if Fetch Goes Past
Last Row
WWW.SRINIMF.COM 42
ï‚Ą Processing an Entire Result Set Common
ï‚Ą Special Form of FOR 
 IN to Manage Cursors
ï‚Ą No Need for Separate OPEN, FETCH and
CLOSE statements
ï‚Ą Requires %ROWTYPE Variable
WWW.SRINIMF.COM 43
ï‚Ą www.srinimf.com
WWW.SRINIMF.COM 44

More Related Content

PPT
02 Writing Executable Statments
rehaniltifat
 
PPTX
Packages in PL/SQL
Pooja Dixit
 
DOC
Oracle notes
Prashant Dadmode
 
PPT
PL/SQL
Vaibhav0
 
PPTX
5. stored procedure and functions
Amrit Kaur
 
PPTX
An Introduction To Oracle Database
Meysam Javadi
 
PPT
Subqueries -Oracle DataBase
Salman Memon
 
PPTX
Sql commands
Pooja Dixit
 
02 Writing Executable Statments
rehaniltifat
 
Packages in PL/SQL
Pooja Dixit
 
Oracle notes
Prashant Dadmode
 
PL/SQL
Vaibhav0
 
5. stored procedure and functions
Amrit Kaur
 
An Introduction To Oracle Database
Meysam Javadi
 
Subqueries -Oracle DataBase
Salman Memon
 
Sql commands
Pooja Dixit
 

What's hot (20)

PPTX
Statements and Conditions in PHP
Maruf Abdullah (Rion)
 
PDF
Inheritance In Java
Arnab Bhaumik
 
PPTX
Introduction to SQL
Amin Choroomi
 
PPT
Core java concepts
Ram132
 
PDF
Access specifiers (Public Private Protected) C++
vivekkumar2938
 
PPTX
Chapter 1 introduction to sql server
baabtra.com - No. 1 supplier of quality freshers
 
PPT
PL/SQL Introduction and Concepts
Bharat Kalia
 
PPTX
PL/SQL - CURSORS
IshaRana14
 
PPTX
Java abstract class & abstract methods
Shubham Dwivedi
 
PDF
Advanced RAC troubleshooting: Network
Riyaj Shamsudeen
 
PPTX
Oracle GoldenGate 21c New Features and Best Practices
Bobby Curtis
 
PDF
Inheritance and interface
Shubham Sharma
 
PPTX
Object oriented database
Md. Hasan Imam Bijoy
 
ODP
Ms sql-server
Md.Mojibul Hoque
 
PPTX
Lecture 7 arrays
manish kumar
 
PPT
SQLMAP Tool Usage - A Heads Up
Mindfire Solutions
 
PPTX
Basic sql Commands
MUHAMMED MASHAHIL PUKKUNNUMMAL
 
PDF
Xtext beyond the defaults - how to tackle performance problems
Holger Schill
 
PDF
SQL Complete Tutorial. All Topics Covered
Danish Mehraj
 
PPT
Sequences and indexes
Balqees Al.Mubarak
 
Statements and Conditions in PHP
Maruf Abdullah (Rion)
 
Inheritance In Java
Arnab Bhaumik
 
Introduction to SQL
Amin Choroomi
 
Core java concepts
Ram132
 
Access specifiers (Public Private Protected) C++
vivekkumar2938
 
Chapter 1 introduction to sql server
baabtra.com - No. 1 supplier of quality freshers
 
PL/SQL Introduction and Concepts
Bharat Kalia
 
PL/SQL - CURSORS
IshaRana14
 
Java abstract class & abstract methods
Shubham Dwivedi
 
Advanced RAC troubleshooting: Network
Riyaj Shamsudeen
 
Oracle GoldenGate 21c New Features and Best Practices
Bobby Curtis
 
Inheritance and interface
Shubham Sharma
 
Object oriented database
Md. Hasan Imam Bijoy
 
Ms sql-server
Md.Mojibul Hoque
 
Lecture 7 arrays
manish kumar
 
SQLMAP Tool Usage - A Heads Up
Mindfire Solutions
 
Basic sql Commands
MUHAMMED MASHAHIL PUKKUNNUMMAL
 
Xtext beyond the defaults - how to tackle performance problems
Holger Schill
 
SQL Complete Tutorial. All Topics Covered
Danish Mehraj
 
Sequences and indexes
Balqees Al.Mubarak
 
Ad

Viewers also liked (20)

PPTX
Oracle Sql developer tutorial
Asad Masood Qazi
 
PPTX
PLSQL Tutorial
Quang Minh Đoàn
 
DOCX
PL/SQL Code for Sample Projects
jwjablonski
 
PPTX
ORACLE PL SQL FOR BEGINNERS
mohdoracle
 
PPT
Oracle: PLSQL
DataminingTools Inc
 
PPT
Oracle Baisc Tutorial
bunny0143
 
DOC
Oracl DBA lab manual
Abdulla Shaik
 
PDF
Database lab manual
feroz haider bangash
 
PDF
Plsql commons
Arnold Reuser
 
PPT
Oracle PLSql 4
Sergio Ronchi
 
PPTX
Writing command macro in stratus cobol
Srinimf-Slides
 
DOCX
Rexx
Kiran Kumar
 
PPT
The Easytrieve Presention by Srinimf
Srinimf-Slides
 
PPTX
Rexx Shih
YiChun Shih; PMP,PMI-ACP
 
PPT
Sort presentation
Ramakrishna Pulikonda
 
PDF
Plsql Ref
arun_ocp
 
PDF
Contract-oriented PLSQL Programming
John Beresniewicz
 
PPTX
Plsql programs
Knowledge Center Computer
 
PPTX
Macro teradata
Srinimf-Slides
 
PPTX
DB2-SQL Part-2
Srinimf-Slides
 
Oracle Sql developer tutorial
Asad Masood Qazi
 
PLSQL Tutorial
Quang Minh Đoàn
 
PL/SQL Code for Sample Projects
jwjablonski
 
ORACLE PL SQL FOR BEGINNERS
mohdoracle
 
Oracle: PLSQL
DataminingTools Inc
 
Oracle Baisc Tutorial
bunny0143
 
Oracl DBA lab manual
Abdulla Shaik
 
Database lab manual
feroz haider bangash
 
Plsql commons
Arnold Reuser
 
Oracle PLSql 4
Sergio Ronchi
 
Writing command macro in stratus cobol
Srinimf-Slides
 
Rexx
Kiran Kumar
 
The Easytrieve Presention by Srinimf
Srinimf-Slides
 
Sort presentation
Ramakrishna Pulikonda
 
Plsql Ref
arun_ocp
 
Contract-oriented PLSQL Programming
John Beresniewicz
 
Plsql programs
Knowledge Center Computer
 
Macro teradata
Srinimf-Slides
 
DB2-SQL Part-2
Srinimf-Slides
 
Ad

Similar to Oracle PLSQL Step By Step Guide (20)

PPT
Oracle_PLSQL.ppt ..
RAMIROENRIQUERAMALLO
 
PPT
Oracle_PLSQL (1).ppt .
RAMIROENRIQUERAMALLO
 
DOC
3963066 pl-sql-notes-only
Ashwin Kumar
 
PPTX
Plsql guide 2
Vinay Kumar
 
PPT
L9 l10 server side programming
Rushdi Shams
 
PPT
PLSQL.ppt
Peter Asane
 
PPT
SQL / PL
srijanani2030
 
PPT
10gplsqlslide-120704232925-phJKKJJKKJpapp01.ppt
Noorien3
 
PPT
05 Creating Stored Procedures
rehaniltifat
 
PPTX
PL_SQL - II.pptx
priyaprakash11
 
PDF
4. plsql 1
vinaya2306
 
PPT
Cursores.ppt
Alan737817
 
PPTX
PL_SQL_1.pptx fvbxcfbhxdfgh .
RAMIROENRIQUERAMALLO
 
PDF
Meg bernal insight2014 4219
Peter Schouboe
 
PDF
Programming in Oracle with PL/SQL
lubna19
 
PDF
Pl sql programme
Dhilip Prakash
 
PDF
Pl sql programme
Dhilip Prakash
 
DOCX
Oracle plsql and d2 k interview question1
Arunkumar Gurav
 
PDF
Oracle 11G Development Training noida Delhi NCR
Shri Prakash Pandey
 
PPTX
PL/SQL___________________________________
NiharikaKeshari
 
Oracle_PLSQL.ppt ..
RAMIROENRIQUERAMALLO
 
Oracle_PLSQL (1).ppt .
RAMIROENRIQUERAMALLO
 
3963066 pl-sql-notes-only
Ashwin Kumar
 
Plsql guide 2
Vinay Kumar
 
L9 l10 server side programming
Rushdi Shams
 
PLSQL.ppt
Peter Asane
 
SQL / PL
srijanani2030
 
10gplsqlslide-120704232925-phJKKJJKKJpapp01.ppt
Noorien3
 
05 Creating Stored Procedures
rehaniltifat
 
PL_SQL - II.pptx
priyaprakash11
 
4. plsql 1
vinaya2306
 
Cursores.ppt
Alan737817
 
PL_SQL_1.pptx fvbxcfbhxdfgh .
RAMIROENRIQUERAMALLO
 
Meg bernal insight2014 4219
Peter Schouboe
 
Programming in Oracle with PL/SQL
lubna19
 
Pl sql programme
Dhilip Prakash
 
Pl sql programme
Dhilip Prakash
 
Oracle plsql and d2 k interview question1
Arunkumar Gurav
 
Oracle 11G Development Training noida Delhi NCR
Shri Prakash Pandey
 
PL/SQL___________________________________
NiharikaKeshari
 

More from Srinimf-Slides (20)

PPTX
software-life-cycle.pptx
Srinimf-Slides
 
PDF
Python Tutorial Questions part-1
Srinimf-Slides
 
PPT
Cics testing and debugging-session 7
Srinimf-Slides
 
PPT
CICS error and exception handling-recovery and restart-session 6
Srinimf-Slides
 
PPT
Cics program, interval and task control commands-session 5
Srinimf-Slides
 
PPT
Cics data access-session 4
Srinimf-Slides
 
PPT
CICS basic mapping support - session 3
Srinimf-Slides
 
PPT
Cics application programming - session 2
Srinimf-Slides
 
PPT
CICS basics overview session-1
Srinimf-Slides
 
PPTX
100 sql queries
Srinimf-Slides
 
PDF
The best Teradata RDBMS introduction a quick refresher
Srinimf-Slides
 
PDF
The best ETL questions in a nut shell
Srinimf-Slides
 
PDF
IMS DC Self Study Complete Tutorial
Srinimf-Slides
 
PPT
How To Master PACBASE For Mainframe In Only Seven Days
Srinimf-Slides
 
PPT
Assembler Language Tutorial for Mainframe Programmers
Srinimf-Slides
 
PPT
PLI Presentation for Mainframe Programmers
Srinimf-Slides
 
PPTX
PL/SQL Interview Questions
Srinimf-Slides
 
PPTX
DB2 SQL-Part-1
Srinimf-Slides
 
PDF
Teradata - Utilities
Srinimf-Slides
 
PPTX
Hirarchical vs RDBMS
Srinimf-Slides
 
software-life-cycle.pptx
Srinimf-Slides
 
Python Tutorial Questions part-1
Srinimf-Slides
 
Cics testing and debugging-session 7
Srinimf-Slides
 
CICS error and exception handling-recovery and restart-session 6
Srinimf-Slides
 
Cics program, interval and task control commands-session 5
Srinimf-Slides
 
Cics data access-session 4
Srinimf-Slides
 
CICS basic mapping support - session 3
Srinimf-Slides
 
Cics application programming - session 2
Srinimf-Slides
 
CICS basics overview session-1
Srinimf-Slides
 
100 sql queries
Srinimf-Slides
 
The best Teradata RDBMS introduction a quick refresher
Srinimf-Slides
 
The best ETL questions in a nut shell
Srinimf-Slides
 
IMS DC Self Study Complete Tutorial
Srinimf-Slides
 
How To Master PACBASE For Mainframe In Only Seven Days
Srinimf-Slides
 
Assembler Language Tutorial for Mainframe Programmers
Srinimf-Slides
 
PLI Presentation for Mainframe Programmers
Srinimf-Slides
 
PL/SQL Interview Questions
Srinimf-Slides
 
DB2 SQL-Part-1
Srinimf-Slides
 
Teradata - Utilities
Srinimf-Slides
 
Hirarchical vs RDBMS
Srinimf-Slides
 

Recently uploaded (20)

PDF
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PPTX
Smart Infrastructure and Automation through IoT Sensors
Rejig Digital
 
PPTX
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PPTX
Comunidade Salesforce SĂŁo Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira JĂșnior
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PPT
L2 Rules of Netiquette in Empowerment technology
Archibal2
 
PDF
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
PDF
Chapter 1 Introduction to CV and IP Lecture Note.pdf
Getnet Tigabie Askale -(GM)
 
PDF
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
Doc9.....................................
SofiaCollazos
 
PDF
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
Smart Infrastructure and Automation through IoT Sensors
Rejig Digital
 
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
Comunidade Salesforce SĂŁo Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira JĂșnior
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
L2 Rules of Netiquette in Empowerment technology
Archibal2
 
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
Chapter 1 Introduction to CV and IP Lecture Note.pdf
Getnet Tigabie Askale -(GM)
 
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Doc9.....................................
SofiaCollazos
 
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 

Oracle PLSQL Step By Step Guide

  • 2. ï‚Ą Originally modeled after ADA  Created for Dept. of Defense ï‚Ą Allows expanded functionality of database applications ï‚Ą Continues to improve with each new database release WWW.SRINIMF.COM 2
  • 3. ï‚Ą Features  Tight integration with SQL â–Ș Supports data types, functions, pseudo-columns, etc.  Increased performance â–Ș A block of statements sent as a single statement  Increased productivity â–Ș Same techniques can be used with most Oracle products  Portability â–Ș Works on any Oracle platform  Tighter security â–Ș Users may access database objects without granted privileges WWW.SRINIMF.COM 3
  • 4. ï‚Ą Declaration section (optional)  Any needed variables declared here ï‚Ą Executable or begin section  Program code such as statements to retrieve or manipulate data in a table ï‚Ą Exception section (optional)  Error traps can catch situations which might ordinarily crash the program WWW.SRINIMF.COM 4
  • 6. ï‚Ą Variables are local to the code block ï‚Ą Names can be up to 30 characters long and must begin with a character ï‚Ą Declaration is like that in a table  Name then data type the semi-colon  Can be initialized using := operator in the declaration  Can be changed with := in the begin section  Can use constraints ï‚Ą Variables can be composite or collection types  Multiple values of different or same type WWW.SRINIMF.COM 6
  • 7.  CHAR ( max_length )  VARCHAR2 ( max_length )  NUMBER ( precision, scale )  BINARY_INTEGER – more efficient than number  RAW ( max_length )  DATE  BOOLEAN (true, false, null)  Also LONG, LONG RAW and LOB types but the capacity is usually less in PL/SQL than SQL WWW.SRINIMF.COM 7
  • 8. ï‚Ą NOT NULL  Can not be empty ï‚Ą CONSTANT  Can not be changed WWW.SRINIMF.COM 8
  • 9. Age number; Last char ( 10 ); DVal Date := Sysdate; SID number not null; Adjust constant number := 1; CanLoop boolean := true WWW.SRINIMF.COM 9
  • 10. ï‚Ą INVALID_NUMBER (ORA-01722)  Attempted to store non-numeric data in a variable with a numeric data type ï‚Ą NO_DATA_FOUND (ORA-01403)  Query resulted in no rows being found ï‚Ą NOT_LOGGED_ON (ORA-01012)  Not currently connected to an Oracle database ï‚Ą TOO_MANY_ROWS (ORA-01422)  A SELECT INTO statement returned more than one row WWW.SRINIMF.COM 10
  • 11. ï‚Ą DUP_VALUE_ON_INDEX (ORA-00001)  Value inserted for a primary key is not unique ï‚Ą VALUE_ERROR (ORA-06502)  The value being placed in a variable is the wrong length or data type ï‚Ą ZERO_DIVIDE (ORA-01476)  An attempt was made to divide a number by zero WWW.SRINIMF.COM 11
  • 13. ï‚Ą IF-THEN ï‚Ą IF-THEN-ELSE ï‚Ą IF-THEN-ELSIF  An alternative to nested IF-THEN_ELSE WWW.SRINIMF.COM 13
  • 18. ï‚Ą The first line is called the Procedure Specification ï‚Ą The remainder is the Procedure Body ï‚Ą A procedure is compiled and loaded in the database as an object ï‚Ą Procedures can have parameters passed to them WWW.SRINIMF.COM 18
  • 19. ï‚Ą Run a procedure with the PL/SQL EXECUTE command ï‚Ą Parameters are enclosed in parentheses WWW.SRINIMF.COM 19
  • 20. ï‚Ą Like a procedure except they return a single value WWW.SRINIMF.COM 20
  • 21. ï‚Ą Associated with a particular table ï‚Ą Automatically executed when a particular event occurs  Insert  Update  Delete  Others WWW.SRINIMF.COM 21
  • 22. ï‚Ą Procedures are explicitly executed by a user or application ï‚Ą Triggers are implicitly executed (fired) when the triggering event occurs ï‚Ą Triggers should not be used as a lazy way to invoke a procedure as they are fired every time the event occurs WWW.SRINIMF.COM 22
  • 24. ï‚Ą The trigger specification names the trigger and indicates when it will fire ï‚Ą The trigger body contains the PL/SQL code to accomplish whatever task(s) need to be performed WWW.SRINIMF.COM 24
  • 26. ï‚Ą A triggers timing has to be specified first  Before (most common) â–Ș Trigger should be fired before the operation â–Ș i.e. before an insert  After â–Ș Trigger should be fired after the operation â–Ș i.e. after a delete is performed WWW.SRINIMF.COM 26
  • 27. ï‚Ą Three types of events are available  DML events  DDL events  Database events WWW.SRINIMF.COM 27
  • 28. ï‚Ą Changes to data in a table  Insert  Update  Delete WWW.SRINIMF.COM 28
  • 29. ï‚Ą Changes to the definition of objects  Tables  Indexes  Procedures  Functions  Others â–Ș Include CREATE, ALTER and DROP statements on these objects WWW.SRINIMF.COM 29
  • 30. ï‚Ą Server Errors ï‚Ą Users Log On or Off ï‚Ą Database Started or Stopped WWW.SRINIMF.COM 30
  • 31. ï‚Ą Can specify one or more events in the specification  i.e. INSERT OR UPDATE OR DELETE ï‚Ą Can specify one or more columns to be associated with a type of event  i.e. BEFORE UPDATE OF SID OR SNAME WWW.SRINIMF.COM 31
  • 32. ï‚Ą The next item in the trigger is the name of the table to be affected WWW.SRINIMF.COM 32
  • 33. ï‚Ą Two levels for Triggers  Row-level trigger â–Ș Requires FOR EACH ROW clause â–Ș If operation affects multiple rows, trigger fires once for each row affected  Statement-level trigger  DML triggers should be row-level  DDL and Database triggers should not be row- level WWW.SRINIMF.COM 33
  • 35. ï‚Ą Conditions Available So Multiple Operations Can Be Dealt With In Same Trigger  Inserting, Updating, Deleting ï‚Ą Column Prefixes Allow Identification Of Value Changes  New, Old WWW.SRINIMF.COM 35
  • 36. ï‚Ą EXCEPTION Data Type Allows Custom Exceptions ï‚Ą RAISE Allows An Exception To Be Manually Occur ï‚Ą RAISE_APPLICATION_ERROR Allows Termination Using A Custom Error Message  Must Be Between -20000 and -20999  Message Can Be Up to 512 Bytes WWW.SRINIMF.COM 36
  • 37. ï‚Ą Cursors Hold Result of an SQL Statement ï‚Ą Two Types of Cursors in PL/SQL  Implicit – Automatically Created When a Query or Manipulation is for a Single Row  Explicit – Must Be Declared by the User â–Ș Creates a Unit of Storage Called a Result Set WWW.SRINIMF.COM 37
  • 38. Result Set MIS380 DATABASE DESIGN 4 MIS202 INFORMATION SYSTEMS 3 <Cursor MIS485 MANAGING TECHNOLOGY4 MIS480 ADVANCED DATABASE 4 WWW.SRINIMF.COM 38
  • 39. ï‚Ą Declaring an Explicit Cursor CURSOR CursorName IS SelectStatement; ï‚Ą Opening an Explicit Cursor OPEN CursorName; ï‚Ą Accessing Rows from an Explicit Cursor FETCH CursorName INTO RowVariables; WWW.SRINIMF.COM 39
  • 40. ï‚Ą Declaring Variables of the Proper Type with %TYPE VarName TableName.FieldName%TYPE; ï‚Ą Declaring Variables to Hold An Entire Row VarName CursorName%ROWTYPE; ï‚Ą Releasing the Storage Area Used by an Explicit Cursor CLOSE CursorName; WWW.SRINIMF.COM 40
  • 41. ï‚Ą LOOP 
 EXIT 
 END LOOP  EXIT with an If Avoids Infinite Loop ï‚Ą LOOP 
 EXIT WHEN 
 END LOOP  Do Not Need An If to Control EXIT ï‚Ą WHILE 
 LOOP 
 END LOOP  Eliminates Need for EXIT ï‚Ą FOR 
 IN 
 END LOOP  Eliminates Need for Initialization of Counter WWW.SRINIMF.COM 41
  • 42. ï‚Ą Need a Way to Fetch Repetitively ï‚Ą Need a Way to Determine How Many Rows to Process With a Cursor  Cursor Attributes â–Ș CursorName%ROWCOUNT – Number of Rows in a Result Set â–Ș CursorName%FOUND – True if a Fetch Returns a Row â–Ș CursorName%NOTFOUND – True if Fetch Goes Past Last Row WWW.SRINIMF.COM 42
  • 43. ï‚Ą Processing an Entire Result Set Common ï‚Ą Special Form of FOR 
 IN to Manage Cursors ï‚Ą No Need for Separate OPEN, FETCH and CLOSE statements ï‚Ą Requires %ROWTYPE Variable WWW.SRINIMF.COM 43