Skip Headers

PL/SQL User's Guide and Reference
10g Release 1 (10.1)

Part Number B10807-01
Go to Documentation Home
Go to Book List
Book List
Go to Table of Contents
Go to Index
Go to Master Index
Master Index
Go to Feedback page

Go to previous page
Go to next page
View PDF


This guide explains the concepts behind the PL/SQL language and shows, with examples, how to use various language features.

This preface contains these topics:


PL/SQL, Oracle's procedural extension of SQL, is an advanced fourth-generation programming language (4GL). It offers software-engineering features such as data encapsulation, overloading, collection types, exceptions, and information hiding. PL/SQL also supports rapid prototyping and development through tight integration with SQL and the Oracle database.

Anyone developing PL/SQL-based applications for Oracle should read this book. This book is intended for programmers, systems analysts, project managers, database administrators, and others who need to automate database operations. People developing applications in other languages can also produce mixed-language applications with parts written in PL/SQL.

To use this guide effectively, you need a working knowledge of the Oracle database, the SQL language, and basic programming constructs such as IF-THEN comparisons, loops, and procedures and functions.

How This Book Is Organized

The PL/SQL User's Guide and Reference contains:

Getting Started with PL/SQL

Chapter 1, " Overview of PL/SQL"

Summarizes the main features of PL/SQL and their advantages. Introduces the basic concepts behind PL/SQL and the general appearance of PL/SQL programs.

Chapter 2, " Fundamentals of the PL/SQL Language"

Focuses on the small-scale aspects of PL/SQL: lexical units, scalar datatypes, user-defined subtypes, data conversion, expressions, assignments, block structure, declarations, and scope.

Chapter 3, " PL/SQL Datatypes"

Discusses PL/SQL's predefined datatypes, which include integer, floating-point, character, Boolean, date, collection, reference, and LOB types. Also discusses user-defined subtypes and data conversion.

Chapter 4, " Using PL/SQL Control Structures"

Shows how to control the flow of execution through a PL/SQL program. Describes conditional, iterative, and sequential control, with control structures such as IF-THEN-ELSE, CASE, and WHILE-LOOP.

Chapter 5, " Using PL/SQL Collections and Records"

Discusses the composite datatypes TABLE, VARRAY, and RECORD. You learn how to reference and manipulate whole collections of data and group data of different types together.

Database Programming with PL/SQL

Chapter 6, " Performing SQL Operations from PL/SQL"

Shows how PL/SQL supports the SQL commands, functions, and operators for manipulating Oracle data. Also shows how to process queries and transactions.

Chapter 7, " Performing SQL Operations with Native Dynamic SQL"

Shows how to build SQL statements and queries at run time.

Software Engineering with PL/SQL

Chapter 8, " Using PL/SQL Subprograms"

Shows how to write and call procedures, functions. It discusses related topics such as parameters, overloading, and different privilege models for subprograms.

Chapter 9, " Using PL/SQL Packages"

Shows how to bundle related PL/SQL types, items, and subprograms into a package. Packages define APIs that can be reused by many applications.

Chapter 10, " Handling PL/SQL Errors"

Shows how to detect and handle PL/SQL errors using exceptions and handlers.

Chapter 11, " Tuning PL/SQL Applications for Performance"

Shows how to improve performance for PL/SQL-based applications.

Chapter 12, " Using PL/SQL Object Types"

Introduces object-oriented programming based on object types. You learn how to write object methods and manipulate objects through PL/SQL.

PL/SQL Language Reference

Chapter 13, " PL/SQL Language Elements"

Shows the syntax of statements, parameters, and other PL/SQL language elements. Also includes usage notes and short examples.


Appendix A, " Sample PL/SQL Programs"

Provides several PL/SQL programs to guide you in writing your own. The sample programs illustrate important concepts and features.

Appendix B, " Understanding CHAR and VARCHAR2 Semantics in PL/SQL "

Explains the subtle but important semantic differences between the CHAR and VARCHAR2 base types.

Appendix C, " Obfuscating Source Code with the PL/SQL Wrap Utility"

Shows you how to run the Wrap Utility, a standalone programming utility that enables you to deliver PL/SQL applications without exposing your source code.

Appendix D, " How PL/SQL Resolves Identifier Names"

Explains how PL/SQL resolves references to names in potentially ambiguous SQL and procedural statements.

Appendix E, " PL/SQL Program Limits"

Explains the compile-time and runtime limits imposed by PL/SQL .

Appendix F, " List of PL/SQL Reserved Words"

Lists the words that are reserved for use by PL/SQL.

Appendix G, " Frequently Asked Questions About PL/SQL"

Provides tips and answers to some of the most common PL/SQL questions.

Related Documentation

For more information, see these Oracle resources:

Various aspects of PL/SQL programming, in particular details for triggers and stored procedures, are covered in Oracle Database Application Developer's Guide - Fundamentals

For extensive information on object-oriented programming using both PL/SQL and SQL features, see Oracle Database Application Developer's Guide - Object-Relational Features

For information about programming with large objects (LOBs), see Oracle Database Application Developer's Guide - Large Objects

For SQL information, see the Oracle Database SQL Reference and Oracle Database Administrator's Guide. For basic Oracle concepts, see Oracle Database Concepts.

Printed documentation is available for sale in the Oracle Store at

To download free release notes, installation documentation, white papers, or other collateral, please visit the Oracle Technology Network (OTN). You must register online before using OTN; registration is free and can be done at

If you already have a username and password for OTN, then you can go directly to the documentation section of the OTN Web site at


This section describes the conventions used in the text and code examples of this documentation set. It describes:

Conventions in Text

We use various conventions in text to help you more quickly identify special terms. The following table describes those conventions and provides examples of their use.

Convention Meaning Example
Bold Bold typeface indicates terms that are defined in the text or terms that appear in a glossary, or both. When you specify this clause, you create an index-organized table.
Italics Italic typeface indicates book titles or emphasis. Oracle Database Concepts

Ensure that the recovery catalog and target database do not reside on the same disk.

UPPERCASE monospace (fixed-width font) Uppercase monospace typeface indicates elements supplied by the system. Such elements include parameters, privileges, datatypes, RMAN keywords, SQL keywords, SQL*Plus or utility commands, packages and methods, as well as system-supplied column names, database objects and structures, usernames, and roles. You can specify this clause only for a NUMBER column.

You can back up the database by using the BACKUP command.

Query the TABLE_NAME column in the USER_TABLES data dictionary view.


lowercase monospace (fixed-width font) Lowercase monospace typeface indicates executables, filenames, directory names, and sample user-supplied elements. Such elements include computer and database names, net service names, and connect identifiers, as well as user-supplied database objects and structures, column names, packages and classes, usernames and roles, program units, and parameter values.

Note: Some programmatic elements use a mixture of UPPERCASE and lowercase. Enter these elements as shown.

Enter sqlplus to open SQL*Plus.

The password is specified in the orapwd file.

Back up the datafiles and control files in the /disk1/oracle/dbs directory.

The department_id, department_name, and location_id columns are in the hr.departments table.

Set the QUERY_REWRITE_ENABLED initialization parameter to true.

Connect as oe user.

The JRepUtil class implements these methods.

lowercase monospace (fixed-width font) italic Lowercase monospace italic font represents placeholders or variables. You can specify the parallel_clause.

Run Uold_release.SQL where old_release refers to the release you installed prior to upgrading.

Conventions in Code Examples

Code examples illustrate SQL, PL/SQL, SQL*Plus, or other command-line statements. They are displayed in a monospace (fixed-width) font and separated from normal text as shown in this example:

SELECT username FROM dba_users WHERE username = 'MIGRATE';

The following table describes typographic conventions used in code examples and provides examples of their use.

Convention Meaning Example
[ ] Brackets enclose one or more optional items. Do not enter the brackets. DECIMAL (digits [ , precision ])
{ } Braces enclose two or more items, one of which is required. Do not enter the braces. {ENABLE | DISABLE}
A vertical bar represents a choice of two or more options within brackets or braces. Enter one of the options. Do not enter the vertical bar. {ENABLE | DISABLE}


... Horizontal ellipsis points indicate either:
  • That we have omitted parts of the code that are not directly related to the example

  • That you can repeat a portion of the code

CREATE TABLE ... AS subquery;

SELECT col1, col2, ... , coln FROM employees;




Vertical ellipsis points indicate that we have omitted several lines of code not directly related to the example.
Other notation You must enter symbols other than brackets, braces, vertical bars, and ellipsis points as shown. acctbal NUMBER(11,2);

acct CONSTANT NUMBER(4) := 3;

Italics Italicized text indicates placeholders or variables for which you must supply particular values. CONNECT SYSTEM/system_password

DB_NAME = database_name

UPPERCASE Uppercase typeface indicates elements supplied by the system. We show these terms in uppercase in order to distinguish them from terms you define. Unless terms appear in brackets, enter them in the order and with the spelling shown. However, because these terms are not case sensitive, you can enter them in lowercase. SELECT last_name, employee_id FROM employees;


DROP TABLE hr.employees;

lowercase Lowercase typeface indicates programmatic elements that you supply. For example, lowercase indicates names of tables, columns, or files.

Note: Some programmatic elements use a mixture of UPPERCASE and lowercase. Enter these elements as shown.

SELECT last_name, employee_id FROM employees;

sqlplus hr/hr


-- A double hyphen begins a single-line comment, which extends to the end of a line. --
/* */ A slash-asterisk and an asterisk-slash delimit a multi-line comment, which can span multiple lines. /* */

Sample Database Tables

Some programming examples in this guide use tables and other objects from the HR schema of the sample database. These tables, such as EMPLOYEES and DEPARTMENTS, are more extensive and realistic than the EMP and DEPT tables used in previous releases.

Documentation Accessibility

Our goal is to make Oracle products, services, and supporting documentation accessible, with good usability, to the disabled community. To that end, our documentation includes features that make information available to users of assistive technology. This documentation is available in HTML format, and contains markup to facilitate access by the disabled community. Standards will continue to evolve over time, and Oracle is actively engaged with other market-leading technology vendors to address technical obstacles so that our documentation can be accessible to all of our customers. For additional information, visit the Oracle Accessibility Program Web site at

Accessibility of Code Examples in Documentation

JAWS, a Windows screen reader, may not always correctly read the code examples in this document. The conventions for writing code require that closing braces should appear on an otherwise empty line; however, JAWS may not always read a line of text that consists solely of a bracket or brace.

Accessibility of Links to External Web Sites in Documentation

This documentation may contain links to Web sites of other companies or organizations that Oracle does not own or control. Oracle neither evaluates nor makes any representations regarding the accessibility of these Web sites.

Reading the Syntax Diagrams

To understand the syntax of a PL/SQL statement, trace through its syntax diagram, reading from left to right and top to bottom.

The diagrams represent Backus-Naur Form (BNF) productions. Within the diagrams, keywords are enclosed in boxes, delimiters in circles, and identifiers in ovals.

Each diagram defines a syntactic element. Every path through the diagram describes a possible form of that element. Follow in the direction of the arrows. If a line loops back on itself, you can repeat the element enclosed by the loop.