Вы находитесь на странице: 1из 14

4/2/2018 Overview of PL/SQL

(//docs.oracle.com/en/)

Sign In (http://www.oracle.com/webapps/redirect/signon?nexturl=https://docs.oracle.com/database/121/LNPLS/overview.htm#LNPLS001)
Home (/) / Database (/en/database/) / Oracle Database Online Documentation 12c Release 1 (12.1) (../index.html) / Database
Administration (../nav/portal_4.htm)

Database PL/SQL Language Reference

1 Overview of PL/SQL
PL/SQL, the Oracle procedural extension of SQL, is a portable, high-performance transaction-processing
language. This overview explains its advantages and briefly describes its main features and its architecture.

Topics

Advantages of PL/SQL (overview.htm#GUID-17166AA4-14DC-48A6-BE92-3FC758DAA940)

Main Features of PL/SQL (overview.htm#GUID-66D23BD1-0489-43B0-8108-FA14CA579B52)

Architecture of PL/SQL (overview.htm#GUID-6C7B2CED-969A-4861-9CDF-25FD804FAE6E)

Advantages of PL/SQL
PL/SQL offers several advantages over other programming languages.

PL/SQL has these advantages:

Tight Integration with SQL (overview.htm#GUID-55025D4B-0300-4AD2-8305-3DE70B966CB3)

High Performance (overview.htm#GUID-E11D9DDC-93F1-46E9-92C7-E360B45C53BE)

High Productivity (overview.htm#GUID-14ABA325-6475-4F86-95ED-1C0632F30459)

Portability (overview.htm#GUID-F5BA9008-16A2-498D-A8E0-02646333D4C4)

Scalability (overview.htm#GUID-73C5D8F4-34D7-4EA5-AAF1-6A6162987E78)

Manageability (overview.htm#GUID-CB5DF243-8DD7-446B-86FA-82D6C9EDDA39)

Support for Object-Oriented Programming (overview.htm#GUID-F1294B5C-603A-474E-A3B3-F4EAE3AF73AC)

Tight Integration with SQL


PL/SQL is tightly integrated with SQL, the most widely used database manipulation language.

For example:

https://docs.oracle.com/database/121/LNPLS/overview.htm#LNPLS001 1/14
4/2/2018
PL/SQL Overview
lets you use all SQL data manipulation, cursor of PL/SQL
control, and transaction control statements, and all SQL
functions, operators, and pseudocolumns.

PL/SQL fully supports SQL data types.

You need not convert between PL/SQL and SQL data types. For example, if your PL/SQL program retrieves a
value from a column of the SQL type VARCHAR2, it can store that value in a PL/SQL variable of the type
VARCHAR2.

You can give a PL/SQL data item the data type of a column or row of a database table without explicitly
specifying that data type (see "Using the %TYPE Attribute (overview.htm#GUID-1A95AA8C-9BA2-4018-B82B-
535D25E24EBF) " and "Using the %ROWTYPE Attribute (overview.htm#GUID-C945E7E2-DDF6-4EC0-95FB-BFE1C2C66708)
").

PL/SQL lets you run a SQL query and process the rows of the result set one at a time (see "Processing a Query
Result Set One Row at a Time (overview.htm#GUID-8B2DD06E-4AC5-479C-9CEF-D212B8C40DA4) ").

PL/SQL functions can be declared and defined in the WITH clauses of SQL SELECT statements (see Oracle
Database SQL Language Reference (../SQLRF/statements_10002.htm#SQLRF01702) ).

PL/SQL supports both static and dynamic SQL. Static SQL is SQL whose full text is known at compile time.
Dynamic SQL is SQL whose full text is not known until run time. Dynamic SQL lets you make your applications
more flexible and versatile. For more information, see PL/SQL Static SQL (static.htm#GUID-A2E4086F-94DC-4CC7-9E4B-
30285BEC3313) and PL/SQL Dynamic SQL (dynamic.htm#GUID-7E2F596F-9CA3-4DC8-8333-0C117962DB73) .

High Performance
PL/SQL lets you send a block of statements to the database, significantly reducing traffic between the application
and the database.

Bind Variables

When you embed a SQL INSERT, UPDATE, DELETE, MERGE, or SELECT statement directly in your PL/SQL code, the
PL/SQL compiler turns the variables in the WHERE and VALUES clauses into bind variables (for details, see
"Resolution of Names in Static SQL Statements (nameresolution.htm#GUID-0D18B5E5-A6F7-45B7-A1FA-F7D930C6999C) ").
Oracle Database can reuse these SQL statements each time the same code runs, which improves performance.

PL/SQL does not create bind variables automatically when you use dynamic SQL, but you can use them with
dynamic SQL by specifying them explicitly (for details, see "EXECUTE IMMEDIATE Statement (dynamic.htm#GUID-
30ADFC05-8DFB-4C8A-831D-426C2E97F217) ").

Subprograms

PL/SQL subprograms are stored in executable form, which can be invoked repeatedly. Because stored
subprograms run in the database server, a single invocation over the network can start a large job. This division of
work reduces network traffic and improves response times. Stored subprograms are cached and shared among
users, which lowers memory requirements and invocation overhead. For more information about subprograms,
see "Subprograms (overview.htm#GUID-8E5695A2-F639-4480-9C61-0AE5CF0C16BC) ".
https://docs.oracle.com/database/121/LNPLS/overview.htm#LNPLS001 2/14
4/2/2018 Overview of PL/SQL

Optimizer

The PL/SQL compiler has an optimizer that can rearrange code for better performance. For more information
about the optimizer, see "PL/SQL Optimizer (tuning.htm#GUID-8BC4231B-2E5C-47D6-BE14-6D75CE14C57E) ".

High Productivity
PL/SQL has many features that save designing and debugging time, and it is the same in all environments.

PL/SQL lets you write compact code for manipulating data. Just as a scripting language like PERL can read,
transform, and write data in files, PL/SQL can query, transform, and update data in a database.

If you learn to use PL/SQL with one Oracle tool, you can transfer your knowledge to other Oracle tools. For an
overview of PL/SQL features, see "Main Features of PL/SQL (overview.htm#GUID-66D23BD1-0489-43B0-8108-
FA14CA579B52) ".

Portability
PL/SQL is a portable and standard language for Oracle development.

You can run PL/SQL applications on any operating system and platform where Oracle Database runs.

Scalability
PL/SQL stored subprograms increase scalability by centralizing application processing on the database server.

The shared memory facilities of the shared server let Oracle Database support thousands of concurrent users on a
single node. For more information about subprograms, see "Subprograms (overview.htm#GUID-8E5695A2-F639-4480-
9C61-0AE5CF0C16BC) ".

For further scalability, you can use Oracle Connection Manager to multiplex network connections. For information
about Oracle Connection Manager, see Oracle Database Net Services Reference (../NETRF/cmctl.htm#NETRF002) .

Manageability
PL/SQL stored subprograms increase manageability because you can maintain only one copy of a subprogram,
on the database server, rather than one copy on each client system.

Any number of applications can use the subprograms, and you can change the subprograms without affecting the
applications that invoke them. For more information about subprograms, see "Subprograms (overview.htm#GUID-
8E5695A2-F639-4480-9C61-0AE5CF0C16BC) ".

Support for Object-Oriented Programming


PL/SQL allows defining object types that can be used in object-oriented designs.

PL/SQL supports object-oriented programming with "Abstract Data Types (overview.htm#GUID-4E7295F2-854D-454F-9001-


CA950FCAAC55) ".
https://docs.oracle.com/database/121/LNPLS/overview.htm#LNPLS001 3/14
Main Features of PL/SQL
4/2/2018 Overview of PL/SQL

PL/SQL combines the data-manipulating power of SQL with the processing power of procedural languages.

When you can solve a problem with SQL, you can issue SQL statements from your PL/SQL program, without
learning new APIs.

Like other procedural programming languages, PL/SQL lets you declare constants and variables, control program
flow, define subprograms, and trap runtime errors.

You can break complex problems into easily understandable subprograms, which you can reuse in multiple
applications.

Topics

Error Handling (overview.htm#GUID-EAC28BE9-598B-4FF1-B0EA-C1AD0884634B)

Blocks (overview.htm#GUID-826B070B-4888-4398-889B-61A3C6B91349)

Variables and Constants (overview.htm#GUID-8514540B-FE23-41E1-9F72-AB8D726DEE8F)

Subprograms (overview.htm#GUID-8E5695A2-F639-4480-9C61-0AE5CF0C16BC)

Packages (overview.htm#GUID-7212C796-0AE8-40EA-998E-E4644916357C)

Triggers (overview.htm#GUID-BE368C32-DC7E-4301-BA72-1A8FB6A73F41)

Input and Output (overview.htm#GUID-38C84AB3-D129-4C6B-A308-4B0CBA3B4D1D)

Data Abstraction (overview.htm#GUID-83189605-83F9-47D9-8515-95F415F721C4)

Control Statements (overview.htm#GUID-91A57FE5-CABE-4FE6-B6B7-00C297B77117)

Conditional Compilation (overview.htm#GUID-4ED4C979-5C1A-4BFA-AEFA-AF152421DE74)

Processing a Query Result Set One Row at a Time (overview.htm#GUID-8B2DD06E-4AC5-479C-9CEF-D212B8C40DA4)

Error Handling
PL/SQL makes it easy to detect and handle errors.

When an error occurs, PL/SQL raises an exception. Normal execution stops and control transfers to the exception-
handling part of the PL/SQL block. You do not have to check every operation to ensure that it succeeded, as in a C
program.

For more information, see PL/SQL Error Handling (errors.htm#GUID-0502DC1A-F0A5-4180-A912-6A5CDC855F56) .

Blocks
The basic unit of a PL/SQL source program is the block, which groups related declarations and statements.

https://docs.oracle.com/database/121/LNPLS/overview.htm#LNPLS001 4/14
A PL/SQL
4/2/2018 block is defined by the keywords DECLARE, BEGIN , EXCEPTION
Overview of PL/SQL , and END. These keywords divide the

block into a declarative part, an executable part, and an exception-handling part. Only the executable part is
required. A block can have a label.

Declarations are local to the block and cease to exist when the block completes execution, helping to avoid
cluttered namespaces for variables and subprograms.

Blocks can be nested: Because a block is an executable statement, it can appear in another block wherever an
executable statement is allowed.

You can submit a block to an interactive tool (such as SQL*Plus or Enterprise Manager) or embed it in an Oracle
Precompiler or OCI program. The interactive tool or program runs the block one time. The block is not stored in the
database, and for that reason, it is called an anonymous block (even if it has a label).

An anonymous block is compiled each time it is loaded into memory, and its compilation has three stages:

1. Syntax checking: PL/SQL syntax is checked, and a parse tree is generated.

2. Semantic checking: Type checking and further processing on the parse tree.

3. Code generation

Note:
An anonymous block is a SQL statement.

For syntax details, see "Block (block.htm#GUID-9ACEB9ED-567E-4E1A-A16A-B8B35214FC9D) ".

Example 1-1 PL/SQL Block Structure

This example shows the basic structure of a PL/SQL block.

<< label >> (optional) DECLARE -- Declarative part (optional) -- Declarations of local
types, variables, & subprograms BEGIN -- Executable part (required) -- Statements (which
can use items declared in declarative part) [EXCEPTION -- Exception-handling part
(optional) -- Exception handlers for exceptions (errors) raised in executable part] END;

Variables and Constants


PL/SQL lets you declare variables and constants, and then use them wherever you can use an expression.

As the program runs, the values of variables can change, but the values of constants cannot.

For more information, see "Declarations (fundamentals.htm#GUID-65F9E0D0-03CD-4C40-829A-7392ACE8F932) " and


"Assigning Values to Variables (fundamentals.htm#GUID-356CB656-68ED-4869-8C67-FE93A78AEC9A) ".

Subprograms
A PL/SQL subprogram is a named PL/SQL block that can be invoked repeatedly.

https://docs.oracle.com/database/121/LNPLS/overview.htm#LNPLS001 5/14
If the
4/2/2018subprogram has parameters, their values can differ for each
Overview invocation. PL/SQL has two types of
of PL/SQL
subprograms, procedures and functions. A function returns a result.

For more information about PL/SQL subprograms, see PL/SQL Subprograms (subprograms.htm#GUID-13BEBBEC-02D4-
48E8-A059-DFEAC4751A3B) .

PL/SQL also lets you invoke external programs written in other languages.

For more information, see "External Subprograms (subprograms.htm#GUID-96B5DE2B-D809-4296-9CDE-B317B81895F8) ".

Packages
A package is a schema object that groups logically related PL/SQL types, variables, constants, subprograms,
cursors, and exceptions.

A package is compiled and stored in the database, where many applications can share its contents. You can think
of a package as an application.

You can write your own packages—for details, see PL/SQL Packages (packages.htm#GUID-C285EC5A-BE50-4192-A88E-
48C0778B34E0) . You can also use the many product-specific packages that Oracle Database supplies. For
information about these, see Oracle Database PL/SQL Packages and Types Reference (../ARPLS/toc.htm) .

Triggers
A trigger is a named PL/SQL unit that is stored in the database and run in response to an event that occurs in the
database.

You can specify the event, whether the trigger fires before or after the event, and whether the trigger runs for each
event or for each row affected by the event. For example, you can create a trigger that runs every time an INSERT
statement affects the EMPLOYEES table.

For more information about triggers, see PL/SQL Triggers (triggers.htm#GUID-217E8B13-29EF-45F3-8D0F-2384F9F1D231) .

Input and Output


Most PL/SQL input and output (I/O) is done with SQL statements that store data in database tables or query those
tables. All other PL/SQL I/O is done with PL/SQL packages that Oracle Database supplies.

Table 1-1 PL/SQL I/O-Processing Packages

Package Description More Information

DBMS_OUTPUT Lets PL/SQL blocks, subprograms, packages, Oracle Database PL/SQL


and triggers display output. Especially useful for Packages and Types Reference
displaying PL/SQL debugging information. (../ARPLS/d_output.htm#ARPLS036)

HTF Has hypertext functions that generate HTML Oracle Database PL/SQL
tags (for example, the HTF.ANCHOR function Packages and Types Reference
generates the HTML anchor tag <A>). (../ARPLS/w_htf.htm#ARPLS390)

https://docs.oracle.com/database/121/LNPLS/overview.htm#LNPLS001 6/14
4/2/2018 Overview of PL/SQL
Package Description More Information

HTP Has hypertext procedures that generate HTML Oracle Database PL/SQL
tags. Packages and Types Reference
(../ARPLS/w_htp.htm#ARPLS391)

DBMS_PIPE Lets two or more sessions in the same instance Oracle Database PL/SQL
communicate. Packages and Types Reference
(../ARPLS/d_pipe.htm#ARPLS038)

UTL_FILE Lets PL/SQL programs read and write operating Oracle Database PL/SQL
system files. Packages and Types Reference
(../ARPLS/u_file.htm#ARPLS069)

UTL_HTTP Lets PL/SQL programs make Hypertext Oracle Database PL/SQL


Transfer Protocol (HTTP) callouts, and access Packages and Types Reference
data on the Internet over HTTP. (../ARPLS/u_http.htm#ARPLS070)

UTL_SMTP Sends electronic mails (emails) over Simple Oracle Database PL/SQL
Mail Transfer Protocol (SMTP) as specified by Packages and Types Reference
RFC821. (../ARPLS/u_smtp.htm#ARPLS074)

To display output passed to DBMS_OUTPUT, you need another program, such as SQL*Plus. To see DBMS_OUTPUT
output with SQL*Plus, you must first issue the SQL*Plus command SET SERVEROUTPUT ON.

Some subprograms in the packages in Table 1-1 (overview.htm#GUID-38C84AB3-D129-4C6B-A308-


4B0CBA3B4D1D__CJACADID) can both accept input and display output, but they cannot accept data directly from the
keyboard. To accept data directly from the keyboard, use the SQL*Plus commands PROMPT and ACCEPT.

See Also:
SQL*Plus User's Guide and Reference (../SQPUG/ch_twelve040.htm#SQPUG099) for information about the
SQL*Plus command SET SERVEROUTPUT ON

SQL*Plus User's Guide and Reference (../SQPUG/ch_twelve032.htm#SQPUG052) for information about the
SQL*Plus command PROMPT

SQL*Plus User's Guide and Reference (../SQPUG/ch_twelve005.htm#SQPUG026) for information about the
SQL*Plus command ACCEPT

Oracle Database SQL Language Reference (../SQLRF/toc.htm) for information about SQL statements

Data Abstraction
Data abstraction lets you work with the essential properties of data without being too involved with details.
https://docs.oracle.com/database/121/LNPLS/overview.htm#LNPLS001 7/14
You
4/2/2018 can design a data structure first, and then design algorithms
Overview of that manipulate it.
PL/SQL

Topics

Cursors (overview.htm#GUID-6E238587-4712-4042-A792-785F1B002F71)

Composite Variables (overview.htm#GUID-AD429E4C-0025-47A0-9A6B-484076CBBAE5)

Using the %ROWTYPE Attribute (overview.htm#GUID-C945E7E2-DDF6-4EC0-95FB-BFE1C2C66708)

Using the %TYPE Attribute (overview.htm#GUID-1A95AA8C-9BA2-4018-B82B-535D25E24EBF)

Abstract Data Types (overview.htm#GUID-4E7295F2-854D-454F-9001-CA950FCAAC55)

Cursors
A cursor is a pointer to a private SQL area that stores information about processing a specific SQL statement or
PL/SQL SELECT INTO statement.

You can use the cursor to retrieve the rows of the result set one at a time. You can use cursor attributes to get
information about the state of the cursor—for example, how many rows the statement has affected so far.

For more information about cursors, see "Cursors Overview (static.htm#GUID-F1FE15F9-5C96-4C4E-B240-B7363D25A8F1) ".

Composite Variables
A composite variable has internal components, which you can access individually.

You can pass entire composite variables to subprograms as parameters. PL/SQL has two kinds of composite
variables, collections and records.

In a collection, the internal components are always of the same data type, and are called elements. You access
each element by its unique index. Lists and arrays are classic examples of collections.

In a record, the internal components can be of different data types, and are called fields. You access each field by
its name. A record variable can hold a table row, or some columns from a table row.

For more information about composite variables, see PL/SQL Collections and Records (composites.htm#GUID-
7115C8B6-62F9-496D-BEC3-F7441DFE148A) .

Using the %ROWTYPE Attribute


The %ROWTYPE attribute lets you declare a record that represents either a full or partial row of a database table or
view.

For every column of the full or partial row, the record has a field with the same name and data type. If the structure
of the row changes, then the structure of the record changes accordingly.

For more information about %ROWTYPE syntax and semantics, see "%ROWTYPE Attribute (rowtype_attribute.htm#GUID-
4E0B9FE2-909D-444A-9B4A-E0243B7FCB99) ". For more details about its usage, see "Declaring Items using the
%ROWTYPE Attribute (composites.htm#GUID-EBF66B92-8A94-4E3A-A837-253D5DA79D5F) ".

https://docs.oracle.com/database/121/LNPLS/overview.htm#LNPLS001 8/14
Using the %TYPE Attribute
4/2/2018 Overview of PL/SQL

The %TYPE attribute lets you declare a data item of the same data type as a previously declared variable or column
(without knowing what that type is).

If the declaration of the referenced item changes, then the declaration of the referencing item changes accordingly.
The %TYPE attribute is particularly useful when declaring variables to hold database values. For more information
about %TYPE syntax and semantics, see "%TYPE Attribute (type_attribute.htm#GUID-EAB44F7E-B2AB-4AC6-B83D-
B586193D75FC) ". For more details about its usage, see "Declaring Items using the %TYPE Attribute
(fundamentals.htm#GUID-2E4B6BBA-08B5-473A-901D-738BD00ABF47) ".

Abstract Data Types


An Abstract Data Type (ADT) consists of a data structure and subprograms that manipulate the data.

The variables that form the data structure are called attributes. The subprograms that manipulate the attributes
are called methods.

ADTs are stored in the database. Instances of ADTs can be stored in tables and used as PL/SQL variables.

ADTs let you reduce complexity by separating a large system into logical components, which you can reuse.

In the static data dictionary view *_OBJECTS, the OBJECT_TYPE of an ADT is TYPE. In the static data dictionary
view *_TYPES, the TYPECODE of an ADT is OBJECT.

For more information about ADTs, see "CREATE TYPE Statement (create_type.htm#GUID-389D603D-FBD0-452A-8414-
240BBBC57034) ".

Note:
ADTs are also called user-defined types and object types.

See Also:
Oracle Database Object-Relational Developer's Guide (../ADOBJ/adobjint.htm#ADOBJ001) for information about
ADTs (which it calls object types)

Control Statements
Control statements are the most important PL/SQL extension to SQL.

PL/SQL has three categories of control statements:

Conditional selection statements, which let you run different statements for different data values.

For more information, see "Conditional Selection Statements (controlstatements.htm#GUID-B7DD4E62-3ED2-41E9-AAE5-


90A78788BB31) ".

Loop statements, which let you repeat the same statements with a series of different data values.

https://docs.oracle.com/database/121/LNPLS/overview.htm#LNPLS001 9/14
For
4/2/2018 more information, see "LOOP Statements (controlstatements.htm#GUID-4CD12F11-2DB8-4B0D-9E04-DF983DCF9358)
Overview of PL/SQL ".

Sequential control statements, which allow you to go to a specified, labeled statement, or to do nothing.

For more information, see "Sequential Control Statements (controlstatements.htm#GUID-7CA9E984-CCB3-4DB8-8D0C-


30BF0C74BA83) ".

Conditional Compilation
Conditional compilation lets you customize the functionality in a PL/SQL application without removing source text.

For example, you can:

Use new features with the latest database release, and disable them when running the application in an older
database release.

Activate debugging or tracing statements in the development environment, and hide them when running the
application at a production site.

For more information, see "Conditional Compilation (fundamentals.htm#GUID-DC23291F-006D-49C4-87DA-6B31F19F162A) ".

Processing a Query Result Set One Row at a Time


PL/SQL lets you issue a SQL query and process the rows of the result set one at a time.

You can use a basic loop, or you can control the process precisely by using individual statements to run the query,
retrieve the results, and finish processing.

Example 1-2 Processing Query Result Rows One at a Time

This example uses a basic loop.

BEGIN FOR someone IN ( SELECT * FROM employees WHERE employee_id < 120 ORDER BY
employee_id ) LOOP DBMS_OUTPUT.PUT_LINE('First name = ' || someone.first_name || ', Last
name = ' || someone.last_name); END LOOP; END; /

Result:

First name = Steven, Last name = King First name = Neena, Last name = Kochhar First name
= Lex, Last name = De Haan First name = Alexander, Last name = Hunold First name = Bruce,
Last name = Ernst First name = David, Last name = Austin First name = Valli, Last name =
Pataballa First name = Diana, Last name = Lorentz First name = Nancy, Last name =
Greenberg First name = Daniel, Last name = Faviet First name = John, Last name = Chen
First name = Ismael, Last name = Sciarra First name = Jose Manuel, Last name = Urman
First name = Luis, Last name = Popp First name = Den, Last name = Raphaely First name =
Alexander, Last name = Khoo First name = Shelli, Last name = Baida First name = Sigal,
Last name = Tobias First name = Guy, Last name = Himuro First name = Karen, Last name =
Colmenares

https://docs.oracle.com/database/121/LNPLS/overview.htm#LNPLS001 10/14
Architecture of PL/SQL
4/2/2018 Overview of PL/SQL

Basic understanding of the PL/SQL architecture is beneficial to PL/SQL programmers.

Topics

PL/SQL Engine (overview.htm#GUID-2D575F6D-71F5-4677-8380-B3DADF144C05)

PL/SQL Units and Compilation Parameters (overview.htm#GUID-DF63BC59-22C2-4BA8-9240-F74D505D5102)

PL/SQL Engine
The PL/SQL compilation and runtime system is an engine that compiles and runs PL/SQL units.

The engine can be installed in the database or in an application development tool, such as Oracle Forms.

In either environment, the PL/SQL engine accepts as input any valid PL/SQL unit. The engine runs procedural
statements, but sends SQL statements to the SQL engine in the database, as shown in Figure 1-1
(overview.htm#GUID-2D575F6D-71F5-4677-8380-B3DADF144C05__I6945) .

Figure 1-1 PL/SQL Engine

Description of "Figure 1-1 PL/SQL Engine" (img_text/lnpls004.htm)


Typically, the database processes PL/SQL units.

When an application development tool processes PL/SQL units, it passes them to its local PL/SQL engine. If a
PL/SQL unit contains no SQL statements, the local engine processes the entire PL/SQL unit. This is useful if the
application development tool can benefit from conditional and iterative control.

For example, Oracle Forms applications frequently use SQL statements to test the values of field entries and do
simple computations. By using PL/SQL instead of SQL, these applications can avoid calls to the database.

PL/SQL Units and Compilation Parameters


https://docs.oracle.com/database/121/LNPLS/overview.htm#LNPLS001 11/14
PL/SQL
4/2/2018 units are affected by PL/SQL compilation parameters
Overview(aofcategory
PL/SQL of database initialization parameters).
Different PL/SQL units—for example, a package specification and its body—can have different compilation
parameter settings.

A PL/SQL unit is one of these:

PL/SQL anonymous block

FUNCTION

LIBRARY

PACKAGE

PACKAGE BODY

PROCEDURE

TRIGGER

TYPE

TYPE BODY

Table 1-2 (overview.htm#GUID-DF63BC59-22C2-4BA8-9240-F74D505D5102__G3260498) summarizes the PL/SQL compilation


parameters. To display the values of these parameters for specified or all PL/SQL units, query the static data
dictionary view ALL_PLSQL_OBJECT_SETTINGS. For information about this view, see Oracle Database Reference
(../REFRN/GUID-7EF7B6E3-50B1-43C3-A56E-40955B47C65D.htm#REFRN20385) .

Table 1-2 PL/SQL Compilation Parameters

Parameter Description

PLSCOPE_SETTINGS Controls the compile-time collection, cross-reference, and storage of


(../REFRN/GUID-E420D72D-4199- PL/SQL source text identifier data. Used by the PL/Scope tool (see Oracle
4444-9D9A- Database Development Guide (../ADFNS/adfns_plscope.htm#ADFNS022) ).
080CBEA09DD4.htm#REFRN10271)
For more information about PLSCOPE_SETTINGS, see Oracle Database
Reference (../REFRN/GUID-E420D72D-4199-4444-9D9A-
080CBEA09DD4.htm#REFRN10271) .

PLSQL_CCFLAGS (../REFRN/GUID- Lets you control conditional compilation of each PL/SQL unit independently.
E27CC5B2-7D1C-4EE1-81B1-
1F2D51EA99CE.htm#REFRN10261) For more information about PLSQL_CCFLAGS, see "How Conditional
Compilation Works (fundamentals.htm#GUID-09361222-5837-427B-B7C7-
D3D425DC89F4) " and Oracle Database Reference (../REFRN/GUID-E27CC5B2-
7D1C-4EE1-81B1-1F2D51EA99CE.htm#REFRN10261) .

https://docs.oracle.com/database/121/LNPLS/overview.htm#LNPLS001 12/14
4/2/2018 Overview of PL/SQL
Parameter Description

PLSQL_CODE_TYPE Specifies the compilation mode for PL/SQL units—INTERPRETED (the


(../REFRN/GUID-19CE54C7-6B2A- default) or NATIVE. For information about which mode to use, see
4F3E-92C5- "Determining Whether to Use PL/SQL Native Compilation (tuning.htm#GUID-
D30AFCD01E3F.htm#REFRN10253) F87C76F7-5044-4A8F-AD73-2A946EFFB31D) ".

If the optimization level (set by PLSQL_OPTIMIZE_LEVEL) is less than 2:

The compiler generates interpreted code, regardless of


PLSQL_CODE_TYPE.

If you specify NATIVE, the compiler warns you that NATIVE was ignored.

For more information about PLSQL_CODE_TYPE, see Oracle Database


Reference (../REFRN/GUID-19CE54C7-6B2A-4F3E-92C5-
D30AFCD01E3F.htm#REFRN10253) .

PLSQL_OPTIMIZE_LEVEL Specifies the optimization level at which to compile PL/SQL units (the
(../REFRN/GUID-364B752A-4335- higher the level, the more optimizations the compiler tries to make).
468C-B4BA-
AAC32D75385A.htm#REFRN10255) PLSQL_OPTIMIZE_LEVEL=1 instructs the PL/SQL compiler to generate and
store code for use by the PL/SQL debugger.

For more information about PLSQL_OPTIMIZE_LEVEL, see "PL/SQL


Optimizer (tuning.htm#GUID-8BC4231B-2E5C-47D6-BE14-6D75CE14C57E) " and
Oracle Database Reference (../REFRN/GUID-DC99AD40-9BDD-4099-9FF8-
26C81087EB56.htm#REFRN10254) .

PLSQL_WARNINGS (../REFRN/GUID- Enables or disables the reporting of warning messages by the PL/SQL
B28D6852-61DB-47E4-B681- compiler, and specifies which warning messages to show as errors.
C185ABF1BF21.htm#REFRN10249)
For more information about PLSQL_WARNINGS, see "Compile-Time
Warnings (errors.htm#GUID-3311B813-3185-4751-A3A6-309B93973366) " and Oracle
Database Reference (../REFRN/GUID-B28D6852-61DB-47E4-B681-
C185ABF1BF21.htm#REFRN10249) .

NLS_LENGTH_SEMANTICS Lets you create CHAR and VARCHAR2 columns using either byte-length or
(../REFRN/GUID-221B0A5E-A17A- character-length semantics.
4CBC-8309-
3A79508466F9.htm#REFRN10124) For more information about byte and character length semantics, see
"CHAR and VARCHAR2 Variables (datatypes.htm#GUID-43BB16CE-9D77-419B-
ACE9-32D8A91B3D43) ".

For more information about NLS_LENGTH_SEMANTICS, see Oracle Database


Reference (../REFRN/GUID-221B0A5E-A17A-4CBC-8309-
3A79508466F9.htm#REFRN10124) .

https://docs.oracle.com/database/121/LNPLS/overview.htm#LNPLS001 13/14
4/2/2018 Overview of PL/SQL
Parameter Description

PERMIT_92_WRAP_FORMAT Specifies whether the 12.1 PL/SQL compiler can use wrapped packages
(../REFRN/GUID-BCE9E606-836E- that were compiled with the 9.2 PL/SQL compiler. The default value is
4535-913B- TRUE.
3B3C834B7E23.htm#REFRN10317)
For more information about wrapped packages, see PL/SQL Source Text
Wrapping (wrap.htm#GUID-AB6FFBAD-DE20-4197-A885-AF81F3766FA2) .

For more information about PERMIT_92_WRAP_FORMAT, see Oracle


Database Reference (../REFRN/GUID-BCE9E606-836E-4535-913B-
3B3C834B7E23.htm#REFRN10317) .

Note:
The compilation parameter PLSQL_DEBUG, which specifies whether to compile PL/SQL units for
debugging, is deprecated. To compile PL/SQL units for debugging, specify PLSQL_OPTIMIZE_LEVEL=1.

The compile-time values of the parameters in Table 1-2 (overview.htm#GUID-DF63BC59-22C2-4BA8-9240-


F74D505D5102__G3260498) are stored with the metadata of each stored PL/SQL unit, which means that you can reuse
those values when you explicitly recompile the unit. (A stored PL/SQL unit is created with one of the "CREATE [
OR REPLACE ] Statements (sqlstatements.htm#GUID-C918310F-F1BB-41D7-9466-B558B70DDFFE__BABBEFJD) ". An
anonymous block is not a stored PL/SQL unit.)

To explicitly recompile a stored PL/SQL unit and reuse its parameter values, you must use an ALTER statement
with both the COMPILE clause and the REUSE SETTINGS clause. All ALTER statements have this clause. For a list of
ALTER statements, see "ALTER Statements (sqlstatements.htm#GUID-C918310F-F1BB-41D7-9466-B558B70DDFFE__BABEFIJF)
".

Page 8 of 100
  (https://docs.oracle.com/database/121/LNPLS/fundamentals.htm)
(https://docs.oracle.com/database/121/LNPLS/release_changes.htm)

(#)

About Oracle (http://www.oracle.com/corporate/index.html) Contact Us (http://www.oracle.com/us/corporate/contact/index.html) Legal Notices

(http://www.oracle.com/us/legal/index.html) Terms of Use (http://www.oracle.com/us/legal/terms/index.html) Your Privacy Rights (http://www.oracle.com/us/legal/privacy/index.html)


Copyright © 1996, 2017, Oracle and/or its affiliates. All rights reserved. (http://www.oracle.com/pls/topic/lookup?ctx=cpyr&id=en-US)

https://docs.oracle.com/database/121/LNPLS/overview.htm#LNPLS001 14/14

Вам также может понравиться