background image
<< Confirming to Drop a Synonym | Creating Standalone Procedures and Functions >>
<< Confirming to Drop a Synonym | Creating Standalone Procedures and Functions >>

Developing and Using Stored Procedures

Developing and Using Stored Procedures 4-1
4
Developing and Using Stored Procedures
This chapter introduces the use of PL/SQL, the imperative language of Oracle
Database.
This chapter contains the following sections:
Overview of Stored Procedures
on page 4-1
Creating and Using Standalone Procedures and Functions
on page 4-2
Creating and Using Packages
on page 4-9
Using Variables and Constants
on page 4-15
Controlling Program Flow
on page 4-22
Using Composite Data Structures; Records
on page 4-29
Retrieving Data from a Set Using Cursors and Cursor Variables
on page 4-32
Using Collections; Index-By Tables
on page 4-38
Handling Errors and Exceptions
on page 4-41
Overview of Stored Procedures
You already know how to interact with the database using SQL, but it is not sufficient
for building enterprise applications. PL/SQL is a third generation language that has
the expected procedural and namespace constructs, and its tight integration with SQL
makes it possible to build complex and powerful applications. Because PL/SQL is
executed in the database, you can include SQL statements in your code without
having to establish a separate connection.
The main types of program units you can create with PL/SQL and store in the
database are standalone procedures and functions, and packages. Once stored in the
database, these PL/SQL components, collectively known as stored procedures, can be
used as building blocks for several different applications.
While standalone procedures and functions are invaluable for testing pieces of
program logic, Oracle recommends that you place all your code inside a package.
Packages are easier to port to another system, and have the additional benefit of
qualifying the names of your program units with the package name. For example, if
you developed a schema-level procedure called
continue
in a previous version of
Oracle Database, your code would not compile when you port it to a newer Oracle
Database installation. This is because Oracle recently introduced the statement
CONTINUE
that exits the current iteration of a loop and transfers control to the next
iteration. If you developed your procedure inside a package, the procedure package_
name
.continue
would have been protected from such name capture.