1. Introduction to PL/SQL
Objective
needs
benefits
type of block
output message
About PL/SQL
Procedural Language extension to SQL
Oracle standard
block structure
PL/SQL Environment
PL/SQL engine
Oracle database server
Benefits of PL/SQL
construct with SQL
performance
modularize
integration with oracle tools
portability
exception handling
PL/SQL Block Structure
declare
variable
cursor
user-defined exception
begin
sql statement
plsql statement
exception
action to perform
end
Block Types
anonymous
procedure
function
Program Constructs
tools construct
db construct
anonymous
store procedure or functions
store package
trigger
object type
Create an Anonymous Block
Execute an Anonymous Block
Test the Output of a PL/SQL Block
2. Declaring PL/SQL Variables
Objectives
Use of Variables
Requirements for Variable Names
Handling Variables in PL/SQL
Declaring and Initializing PL/SQL Variables
Delimiters in String Literals
Type of Variables
Guidelines for Declaring and Initializing PL/SQL Variables
Scalar Data Types
Base Scalar Data Types
Declaring Scalar Variables
%TYPE Attribute
Declaring Variables with the %TYPE Attribute
Declaring Boolean Variables
Bind Variables
Printing Bind Variables
LOB Data Type Variables
Composite Data Types
3. Writing Executable Statements
Objectives
Lexical Units in a PL/SQL Block
PL/SQL Block Syntax and Guidelines
Commenting Code
SQL Function in PL/SQL
SQL Functions in PL/SQL: Examples
Using Sequences in PL/SQL Expressions
Data Type Conversion
Nested Blocks
Variable Scope and Visibility
Qualify and Identifier
Quiz: Determining Variable Scope
Operations in PL/SQL
Examples
Programming Guidelines
Indenting Code
4. Interacting with the Oracle Database Server
Objectives
SQL Statements in PL/SQL
select Statement in PL/SQL
Retrieving Data in PL/SQL
Naming Conventions
Using PL/SQL to Manipulate Data
Inserting Data
Updating Data
Deleting Data
Merging Rows
SQL Cursor
SQL Cursor Attributes for Implicit Cursors
5. Writing Control Structures
Objectives
Controlling Flow of Execution
IF Statement
Simple IF Statement
IF THEN ELSE Statement
IF ELSIF ELSE Clause
NULL Value in IF Statement
CASE Expressions
Example
Searched CASE Expressions
CASE Statement
Handling Nulls
Logic Tables
Boolean Conditions
Iterative Control: LOOP Statements
Basic Loops
WHILE Loops
FOR Loops
Guidelines for Loops
Nested Loops and Lables
PL/SQL CONTINUE Statement
Example
6. Working with Composite Data Types
Objectives
Composite Data Types
PL/SQL Records
Creating a PL/SQL Record
PL/SQL Record Structure
%ROWTYPE Attribute
Example
Advantages of Using %ROWTYPE
Inserting a Record by Using %ROWTYPE
Updating a Row in a Table by Using a Record
INDEX BY Tables or Associative Arrays
Creating an INDEX BY Table
INDEX BY Table Structure
Creating and INDEX BY Table
Using INDEX BY Table Methods
INDEX BY Table of Records
Example
Nested Tables
VARRAY
7. Using Explicit Cursors
Objectives
Cursors
Explicit Cursor Operations
Controlling Explicit Cursors
Declaring the Cursor
Opening the Cursor
Fetching Data from the Cursor
Closing the Cursor
Cursors and Records
Cursor FOR Loops
Explicit Cursor Attributes
%ISOPEN Attribute
%ROWCOUNT and %NOTFOUND% Example
Cursor FOR Loops Using Subqueries
Cursors with Parameters
FOR UPDATE Clause
WHERE CURRENT OF Clause
Cursor with Subqueries
8. Handling Exceptions
Objectives
Example of an Exception
Handling Exceptions with PL/SQL
Handling Exceptions
Exception Types
Trapping Exceptions
Guidelines for Trapping Exceptions
Trapping Predefined Oracle Server Errors
Trapping Non-Predefined Oracle Server Errors
Non-Predefined Error
Functions for Trapping Exceptions
Trapping User-Defined Exceptions
Propagating Exceptions in a Subblock
RAISE_APPLICATION_ERROR Procedure
9. Creating Stored Procedures and Functions
Objectives
Procedures and Functions
Differences between Anonymous Blocks and Subprograms
Procedure: Syntax
Procedure: Example
Invoking the Procedure
Function: Syntax
Function: Example
Invoking the Function
Passing a Parameter to the Function
Invoking the Function with a Parameter