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

What's hot

Sql – Structured Query Language
Sql – Structured Query LanguageSql – Structured Query Language
Sql – Structured Query Languagepandey3045_bit
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functionsfarwa waqar
 
Oracle Database DML DDL and TCL
Oracle Database DML DDL and TCL Oracle Database DML DDL and TCL
Oracle Database DML DDL and TCL Abdul Rehman
 
Advanced Sql Training
Advanced Sql TrainingAdvanced Sql Training
Advanced Sql Trainingbixxman
 
PL/SQL Fundamentals I
PL/SQL Fundamentals IPL/SQL Fundamentals I
PL/SQL Fundamentals INick Buytaert
 
10 Creating Triggers
10 Creating Triggers10 Creating Triggers
10 Creating Triggersrehaniltifat
 
Packages in PL/SQL
Packages in PL/SQLPackages in PL/SQL
Packages in PL/SQLPooja Dixit
 
Exception handling in plsql
Exception handling in plsqlException handling in plsql
Exception handling in plsqlArun Sial
 
Difference Between Sql - MySql and Oracle
Difference Between Sql - MySql and OracleDifference Between Sql - MySql and Oracle
Difference Between Sql - MySql and OracleSteve Johnson
 
PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts Bharat Kalia
 
Including Constraints -Oracle Data base
Including Constraints -Oracle Data base Including Constraints -Oracle Data base
Including Constraints -Oracle Data base Salman Memon
 

What's hot (20)

Sql – Structured Query Language
Sql – Structured Query LanguageSql – Structured Query Language
Sql – Structured Query Language
 
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with ExamplesDML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
 
Sql and Sql commands
Sql and Sql commandsSql and Sql commands
Sql and Sql commands
 
PL/SQL TRIGGERS
PL/SQL TRIGGERSPL/SQL TRIGGERS
PL/SQL TRIGGERS
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
 
Oracle Database DML DDL and TCL
Oracle Database DML DDL and TCL Oracle Database DML DDL and TCL
Oracle Database DML DDL and TCL
 
Advanced Sql Training
Advanced Sql TrainingAdvanced Sql Training
Advanced Sql Training
 
PL/SQL Fundamentals I
PL/SQL Fundamentals IPL/SQL Fundamentals I
PL/SQL Fundamentals I
 
PLSQL
PLSQLPLSQL
PLSQL
 
10 Creating Triggers
10 Creating Triggers10 Creating Triggers
10 Creating Triggers
 
Packages in PL/SQL
Packages in PL/SQLPackages in PL/SQL
Packages in PL/SQL
 
Basic SQL and History
 Basic SQL and History Basic SQL and History
Basic SQL and History
 
PL/SQL
PL/SQLPL/SQL
PL/SQL
 
Chapter 4 Structured Query Language
Chapter 4 Structured Query LanguageChapter 4 Structured Query Language
Chapter 4 Structured Query Language
 
Exception handling in plsql
Exception handling in plsqlException handling in plsql
Exception handling in plsql
 
plsql les10
 plsql les10 plsql les10
plsql les10
 
Difference Between Sql - MySql and Oracle
Difference Between Sql - MySql and OracleDifference Between Sql - MySql and Oracle
Difference Between Sql - MySql and Oracle
 
PLSQL Cursors
PLSQL CursorsPLSQL Cursors
PLSQL Cursors
 
PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts
 
Including Constraints -Oracle Data base
Including Constraints -Oracle Data base Including Constraints -Oracle Data base
Including Constraints -Oracle Data base
 

Viewers also liked (20)

Oracle Sql developer tutorial
Oracle Sql developer tutorialOracle Sql developer tutorial
Oracle Sql developer tutorial
 
PLSQL Tutorial
PLSQL TutorialPLSQL Tutorial
PLSQL Tutorial
 
PL/SQL Code for Sample Projects
PL/SQL Code for Sample ProjectsPL/SQL Code for Sample Projects
PL/SQL Code for Sample Projects
 
Oracle: PLSQL
Oracle: PLSQLOracle: PLSQL
Oracle: PLSQL
 
Oracle Baisc Tutorial
Oracle Baisc TutorialOracle Baisc Tutorial
Oracle Baisc Tutorial
 
Oracl DBA lab manual
Oracl DBA lab manualOracl DBA lab manual
Oracl DBA lab manual
 
Database lab manual
Database lab manualDatabase lab manual
Database lab manual
 
Plsql commons
Plsql commons Plsql commons
Plsql commons
 
Oracle PLSql 4
Oracle PLSql 4Oracle PLSql 4
Oracle PLSql 4
 
Writing command macro in stratus cobol
Writing command macro in stratus cobolWriting command macro in stratus cobol
Writing command macro in stratus cobol
 
Rexx
RexxRexx
Rexx
 
The Easytrieve Presention by Srinimf
The Easytrieve Presention by SrinimfThe Easytrieve Presention by Srinimf
The Easytrieve Presention by Srinimf
 
Rexx Shih
Rexx ShihRexx Shih
Rexx Shih
 
Sort presentation
Sort presentationSort presentation
Sort presentation
 
Plsql Ref
Plsql RefPlsql Ref
Plsql Ref
 
Contract-oriented PLSQL Programming
Contract-oriented PLSQL ProgrammingContract-oriented PLSQL Programming
Contract-oriented PLSQL Programming
 
Plsql programs
Plsql programsPlsql programs
Plsql programs
 
Macro teradata
Macro teradataMacro teradata
Macro teradata
 
DB2-SQL Part-2
DB2-SQL Part-2DB2-SQL Part-2
DB2-SQL Part-2
 
PL/SQL Interview Questions
PL/SQL Interview QuestionsPL/SQL Interview Questions
PL/SQL Interview Questions
 

Similar to Introduction to PL/SQL Programming

DBA Commands and Concepts That Every Developer Should Know
DBA Commands and Concepts That Every Developer Should KnowDBA Commands and Concepts That Every Developer Should Know
DBA Commands and Concepts That Every Developer Should KnowAlex Zaballa
 
12c Database new features
12c Database new features12c Database new features
12c Database new featuresSandeep Redkar
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...Alex Zaballa
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...Alex Zaballa
 
Introduction to Threading in .Net
Introduction to Threading in .NetIntroduction to Threading in .Net
Introduction to Threading in .Netwebhostingguy
 
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)Dave Stokes
 
2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...
2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...
2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...Jürgen Ambrosi
 
Introduction to SQLite in Adobe AIR
Introduction to SQLite in Adobe AIRIntroduction to SQLite in Adobe AIR
Introduction to SQLite in Adobe AIRPeter Elst
 
L9 l10 server side programming
L9 l10  server side programmingL9 l10  server side programming
L9 l10 server side programmingRushdi Shams
 
Advanced plsql mock_assessment
Advanced plsql mock_assessmentAdvanced plsql mock_assessment
Advanced plsql mock_assessmentSaurabh K. Gupta
 
3963066 pl-sql-notes-only
3963066 pl-sql-notes-only3963066 pl-sql-notes-only
3963066 pl-sql-notes-onlyAshwin Kumar
 
SQL Server 2008 Performance Enhancements
SQL Server 2008 Performance EnhancementsSQL Server 2008 Performance Enhancements
SQL Server 2008 Performance Enhancementsinfusiondev
 

Similar to Introduction to PL/SQL Programming (20)

DBA Commands and Concepts That Every Developer Should Know
DBA Commands and Concepts That Every Developer Should KnowDBA Commands and Concepts That Every Developer Should Know
DBA Commands and Concepts That Every Developer Should Know
 
12c Database new features
12c Database new features12c Database new features
12c Database new features
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
 
Introduction to Threading in .Net
Introduction to Threading in .NetIntroduction to Threading in .Net
Introduction to Threading in .Net
 
IR SQLite Session #1
IR SQLite Session #1IR SQLite Session #1
IR SQLite Session #1
 
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
 
Oracle SQL Basics
Oracle SQL BasicsOracle SQL Basics
Oracle SQL Basics
 
2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...
2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...
2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...
 
Introduction to SQLite in Adobe AIR
Introduction to SQLite in Adobe AIRIntroduction to SQLite in Adobe AIR
Introduction to SQLite in Adobe AIR
 
L9 l10 server side programming
L9 l10  server side programmingL9 l10  server side programming
L9 l10 server side programming
 
Advanced plsql mock_assessment
Advanced plsql mock_assessmentAdvanced plsql mock_assessment
Advanced plsql mock_assessment
 
Sql server T-sql basics ppt-3
Sql server T-sql basics  ppt-3Sql server T-sql basics  ppt-3
Sql server T-sql basics ppt-3
 
Les21
Les21Les21
Les21
 
Ibm db2 case study
Ibm db2 case studyIbm db2 case study
Ibm db2 case study
 
Oracle notes
Oracle notesOracle notes
Oracle notes
 
3963066 pl-sql-notes-only
3963066 pl-sql-notes-only3963066 pl-sql-notes-only
3963066 pl-sql-notes-only
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
SQL Server 2008 Performance Enhancements
SQL Server 2008 Performance EnhancementsSQL Server 2008 Performance Enhancements
SQL Server 2008 Performance Enhancements
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 

More from Srinimf-Slides

software-life-cycle.pptx
software-life-cycle.pptxsoftware-life-cycle.pptx
software-life-cycle.pptxSrinimf-Slides
 
Python Tutorial Questions part-1
Python Tutorial Questions part-1Python Tutorial Questions part-1
Python Tutorial Questions part-1Srinimf-Slides
 
Cics testing and debugging-session 7
Cics testing and debugging-session 7Cics testing and debugging-session 7
Cics testing and debugging-session 7Srinimf-Slides
 
CICS error and exception handling-recovery and restart-session 6
CICS error and exception handling-recovery and restart-session 6CICS error and exception handling-recovery and restart-session 6
CICS error and exception handling-recovery and restart-session 6Srinimf-Slides
 
Cics program, interval and task control commands-session 5
Cics program, interval and task control commands-session 5Cics program, interval and task control commands-session 5
Cics program, interval and task control commands-session 5Srinimf-Slides
 
Cics data access-session 4
Cics data access-session 4Cics data access-session 4
Cics data access-session 4Srinimf-Slides
 
CICS basic mapping support - session 3
CICS basic mapping support - session 3CICS basic mapping support - session 3
CICS basic mapping support - session 3Srinimf-Slides
 
Cics application programming - session 2
Cics   application programming - session 2Cics   application programming - session 2
Cics application programming - session 2Srinimf-Slides
 
CICS basics overview session-1
CICS basics overview session-1CICS basics overview session-1
CICS basics overview session-1Srinimf-Slides
 
The best Teradata RDBMS introduction a quick refresher
The best Teradata RDBMS introduction a quick refresherThe best Teradata RDBMS introduction a quick refresher
The best Teradata RDBMS introduction a quick refresherSrinimf-Slides
 
The best ETL questions in a nut shell
The best ETL questions in a nut shellThe best ETL questions in a nut shell
The best ETL questions in a nut shellSrinimf-Slides
 
IMS DC Self Study Complete Tutorial
IMS DC Self Study Complete TutorialIMS DC Self Study Complete Tutorial
IMS DC Self Study Complete TutorialSrinimf-Slides
 
How To Master PACBASE For Mainframe In Only Seven Days
How To Master PACBASE For Mainframe In Only Seven DaysHow To Master PACBASE For Mainframe In Only Seven Days
How To Master PACBASE For Mainframe In Only Seven DaysSrinimf-Slides
 
Assembler Language Tutorial for Mainframe Programmers
Assembler Language Tutorial for Mainframe ProgrammersAssembler Language Tutorial for Mainframe Programmers
Assembler Language Tutorial for Mainframe ProgrammersSrinimf-Slides
 
PLI Presentation for Mainframe Programmers
PLI Presentation for Mainframe ProgrammersPLI Presentation for Mainframe Programmers
PLI Presentation for Mainframe ProgrammersSrinimf-Slides
 
20 DFSORT Tricks For Zos Users - Interview Questions
20 DFSORT Tricks For Zos Users - Interview Questions20 DFSORT Tricks For Zos Users - Interview Questions
20 DFSORT Tricks For Zos Users - Interview QuestionsSrinimf-Slides
 

More from Srinimf-Slides (20)

software-life-cycle.pptx
software-life-cycle.pptxsoftware-life-cycle.pptx
software-life-cycle.pptx
 
Python Tutorial Questions part-1
Python Tutorial Questions part-1Python Tutorial Questions part-1
Python Tutorial Questions part-1
 
Cics testing and debugging-session 7
Cics testing and debugging-session 7Cics testing and debugging-session 7
Cics testing and debugging-session 7
 
CICS error and exception handling-recovery and restart-session 6
CICS error and exception handling-recovery and restart-session 6CICS error and exception handling-recovery and restart-session 6
CICS error and exception handling-recovery and restart-session 6
 
Cics program, interval and task control commands-session 5
Cics program, interval and task control commands-session 5Cics program, interval and task control commands-session 5
Cics program, interval and task control commands-session 5
 
Cics data access-session 4
Cics data access-session 4Cics data access-session 4
Cics data access-session 4
 
CICS basic mapping support - session 3
CICS basic mapping support - session 3CICS basic mapping support - session 3
CICS basic mapping support - session 3
 
Cics application programming - session 2
Cics   application programming - session 2Cics   application programming - session 2
Cics application programming - session 2
 
CICS basics overview session-1
CICS basics overview session-1CICS basics overview session-1
CICS basics overview session-1
 
100 sql queries
100 sql queries100 sql queries
100 sql queries
 
The best Teradata RDBMS introduction a quick refresher
The best Teradata RDBMS introduction a quick refresherThe best Teradata RDBMS introduction a quick refresher
The best Teradata RDBMS introduction a quick refresher
 
The best ETL questions in a nut shell
The best ETL questions in a nut shellThe best ETL questions in a nut shell
The best ETL questions in a nut shell
 
IMS DC Self Study Complete Tutorial
IMS DC Self Study Complete TutorialIMS DC Self Study Complete Tutorial
IMS DC Self Study Complete Tutorial
 
How To Master PACBASE For Mainframe In Only Seven Days
How To Master PACBASE For Mainframe In Only Seven DaysHow To Master PACBASE For Mainframe In Only Seven Days
How To Master PACBASE For Mainframe In Only Seven Days
 
Assembler Language Tutorial for Mainframe Programmers
Assembler Language Tutorial for Mainframe ProgrammersAssembler Language Tutorial for Mainframe Programmers
Assembler Language Tutorial for Mainframe Programmers
 
PLI Presentation for Mainframe Programmers
PLI Presentation for Mainframe ProgrammersPLI Presentation for Mainframe Programmers
PLI Presentation for Mainframe Programmers
 
DB2 SQL-Part-1
DB2 SQL-Part-1DB2 SQL-Part-1
DB2 SQL-Part-1
 
Teradata - Utilities
Teradata - UtilitiesTeradata - Utilities
Teradata - Utilities
 
Hirarchical vs RDBMS
Hirarchical vs RDBMSHirarchical vs RDBMS
Hirarchical vs RDBMS
 
20 DFSORT Tricks For Zos Users - Interview Questions
20 DFSORT Tricks For Zos Users - Interview Questions20 DFSORT Tricks For Zos Users - Interview Questions
20 DFSORT Tricks For Zos Users - Interview Questions
 

Recently uploaded

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 

Recently uploaded (20)

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

Introduction to PL/SQL Programming

  • 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