You are on page 1of 18

Oracle8i™ PL/SQL™ —

New Features and Future Directions


An Oracle Technical White Paper
March 1999
INTRODUCTION

PL/SQL is Oracle’s procedural extension to industry-standard SQL. It is a full-fledged programming


language that integrates many features, such as data encapsulation, information hiding, overloading,
and exception handling. In addition to providing these capabilities, PL/SQL naturally, efficiently,
and safely extends SQL.

PL/SQL’s primary strength is in providing a server-side, stored procedure language that is easy-to-
use, seamless with SQL, robust, portable, and secure. Thus, it offers a platform for robust, high-
performing enterprise applications, not only for our Fortune 500 customers, but also for Oracle®
Applications, which have over 4 million lines of PL/SQL code.
®
Furthermore, the PL/SQL compiler and interpreter are also embedded in Oracle Developer,
providing developers with a consistent and leveraged development model on both the client and
®
server side. For instance, developers can use Oracle Designer to design applications, and generate
the necessary client side (Oracle Forms) application logic in PL/SQL, while generating PL/SQL stored
procedures within the server, to capture their business rules and database logic.

Moreover, PL/SQL stored procedures can be called from a number of Oracle clients, such as Pro*C
® ®
or Oracle Call Interface, and from Oracle Reports and Oracle Forms. These capabilities, along with
PL/SQL’s support for dynamic linking and remote procedure calls, create a portable, embeddable
engine that provides a powerful distributed programming environment.

With Oracle8i, we have significantly enhanced PL/SQL to address customer needs in the areas of

performance, application development, and Java integration. With the release of Oracle8i, the
Database Server supports two major programming languages, PL/SQL and Java™. Oracle believes
that, in a majority of situations, customers will use a mix of these languages for application
development. This will leverage the specific strengths of the individual languages. Because it works
seamlessly with SQL, PL/SQL is the best language for SQL programmers and SQL-centered
applications, while Java is a general-purpose language for more general applications. This paper
describes Oracle8i PL/SQL features, integration with Java, PL/SQL and the Internet (web publishing
capabilities), as well as discusses our future directions.

Oracle8i PL/SQL — New Features and Future Directions 2


March 1999
SUMMARY OF ORACLE8i PL/SQL FEATURES

As shown in the table below, several new capabilities have been added in Oracle8 i PL/SQL:

Area Feature
Performance User-Visible Performance Features:
−= Profiling
−= Bulk Binds For Faster Data Transfer Between PL/SQL and SQL
−= Faster NOCOPY Parameter Passing
−= Native Dynamic SQL
Transparent Performance Improvements:
−= Optimization Of Package Standard Built-Ins
−= Faster Anonymous Block Execution
−= Faster RPC Parameter Passing

Application Debugging:
Development −= Debugging
Support −= Tracing
−= Code Coverage
−= Better Error Messages
Ease-of-Use Enhancements:
−= Package Body-Size Limit Increased
−= Purity Simplification
−= External Procedure Callbacks Using Pro*C
−= SQL Query On PL/SQL Table
New Features:
−= Autonomous Transactions
−= Native Dynamic SQL
−= Invoker’s Rights
−= Objects and Extensibility Enhancements

Internet: Web Using The PL/SQL Cartridge To Publish Your Data From the
HTML Publishing Database Onto Your Browser
Integration With Java Seamless Integration With Java

These features are discussed in detail in the following sections.

Oracle8i PL/SQL — New Features and Future Directions 3


March 1999
PERFORMANCE AND ANALYSIS FEATURES

Performance has been improved in Oracle8i PL/SQL along two dimensions:

•= User-Visible Performance Features

•= Transparent Performance Improvements

User-visible performance features provide substantial performance gains, via simple new syntax.
These features can be leveraged by making explicit changes to the application code. Transparent
performance improvements are internal improvements resulting in faster applications. They can be
leveraged by simply upgrading to Oracle8i.

USER-VISIBLE PERFORMANCE FEATURES

Several new features have been added to PL/SQL, including profiling, bulk binds and NOCOPY.
They enable the user to analyze and improve performance.

Profiling

As Oracle8i PL/SQL users develop increasingly large numbers of PL/SQL component packages, the
need to identify and isolate performance problems becomes critical. Oracle8i provides a profiler that
analyzes existing PL/SQL applications, locates bottlenecks, then focuses on improving performance,
by eliminating the bottleneck.

The current support for profiling is our first step in helping third party tool vendors leverage this
application program interface (API), and build tools to support this capability. Using this API, it is
possible to generate profiling information for all named library units used in a single session. The
profiling information is stored in a database, to help generate information on time spent in each
PL/SQL line, module, and routine.

The current release gathers information, at the virtual machine level, that includes:

•= The total number of times each line has been executed.

•= The total amount of time spent executing that line.

•= The minimum and maximum times spent on a particular execution of that line.

Oracle8i PL/SQL — New Features and Future Directions 4


March 1999
Tool vendors can use these features for building graphical, customizable, profiling products. Also, a
sample textual report writer is provided in the current release.

Bulk Binds: Faster Data Transfer Between PL/SQL and SQL

The PL/SQL interpreter executes all procedural statements, but sends the SQL statements to the SQL
engine, which parses and executes the SQL statements. In some cases, it returns data to the PL/SQL
engine. Although this execution path has been heavily optimized to support faster execution of the
embedded SQL statements, the PL/SQL to SQL context switch adds some overhead. This
performance drain is magnified when SQL statements are nested in loops, and, therefore, executed
several times.

The bulk binds features allow users to decrease overhead, by operating on multiple rows in a single
DML statement. This improves performance, by reducing the number of context switches. Using
bulk binds, entire collections (and not just the individual collection elements) can be passed back and
forth between the PL/SQL and SQL engine. New syntax, such as FORALL and BULK COLLECT,
has been added to Oracle8i PL/SQL, to support bulk binds. Finally, sample applications have shown
30 percent performance improvement in our internal benchmark tests, as a result of using these
new features.

Oracle8i PL/SQL — New Features and Future Directions 5


March 1999
ÿBefore Oracle8i: ÿIn Oracle8i with the Bulk Binds
ÿPL/SQL calls the SQL engine multiple times feature:
(once for every new Order). ÿPL/SQL calls the SQL engine only once (with
a single bulk bind of all the new Orders).
... ...
/* /*
* Assume that you have * Assume that you have
PL/SQL tables called OrderId, PL/SQL tables called OrderId,
* OrderDate, etc. (one for * OrderDate, etc. (one for
each column of table Orders) each column of table Orders)
* which have been filled * which have been filled
appropriately with all the appropriately with all the
* new Orders that need to * new Orders that need to
be inserted into the database. be inserted into the database.
* Assume that you have 1000 * Assume that you have 1000
orders. orders.
*/ */
FOR i IN 1..1000 FORALL i IN 1..1000
LOOP INSERT INTO Orders
INSERT INTO Orders VALUES(OrderId(i),
VALUES(OrderId(i), OrderDate(i)…);
OrderDate(i)…);
END LOOP;

NOCOPY: Faster Parameter Passing

PL/SQL supports three parameter passing modes:

•= IN  Parameters are passed by reference.

•= IN OUT  Parameters are implemented as copy-in/copy-out.

•= OUT  Parameters are implemented as copy-out.

This parameter copying protects the original values of the arguments, if exceptions are raised in the
called function or procedure. However, it imposes CPU and memory overhead, especially when the
parameters are large data structures, such as large strings or collections. The current solution for this
problem is cumbersome and memory intensive, as parameters are kept as package global variables
and used by all the programs, instead of passing parameters around.

In Oracle8i, PL/SQL supports a new “NOCOPY” modifier that avoids this copy overhead, by
allowing IN OUT and OUT parameters to be passed efficiently by reference, when possible. There
are certain limitations when copies still have to be made to preserve semantics. NOCOPY provides

Oracle8i PL/SQL — New Features and Future Directions 6


March 1999
significant benefits, especially when passing large parameters. For example, during benchmarking,
improvements between 30 to 200 percent were observed for medium-to-large PL/SQL tables passed
as parameters. The following example shows the use of the NOCOPY modifier:

/*
* Example of NOCOPY:
* The INOUT parameter “word_list” in procedure “add_entry”
is passed by reference when possible
*/
TYPE Definition IS RECORD
(
word VARCHAR2(20),
meaning VARCHAR(200)
);

TYPE Dictionary IS VARRAY(2000) OF Definition;

CREATE PROCEDURE add_entry(word_list IN OUT NOCOPY Dictionary)


IS
BEGIN
...
END;

Native Dynamic SQL

Native Dynamic SQL provides substantial performance benefits, in addition to being easy to use.
Refer to the “New Application Development Features” section below for more details.

TRANSPARENT PERFORMANCE IMPROVEMENTS

Oracle8i provides a tuned runtime engine in several places, to allow existing applications to
transparently run faster, without changes to application code. These improvements include:

•= Optimization of Package Standard Built-Ins

Calls to Standard built-ins (e.g., TO_CHAR, TO_DATE, SUBSTR, etc.) are significantly faster, as
most applications use built-ins heavily. Our benchmark runs have shown performance gains
between 10 - 30 percent.

Oracle8i PL/SQL — New Features and Future Directions 7


March 1999
•= Faster Anonymous Block Execution

−= Accessing elements of host array bind variables is significantly faster in Oracle8i PL/SQL.

−= Host binds that are used only in SQL statements in anonymous PL/SQL blocks have been
optimized, by avoiding unnecessary temporaries.

−= Redundant rebinds for host bind variables to SQL statements in an anonymous blocks have been
eliminated for repeated executions of the anonymous block.

•= Faster RPC Parameter Passing

Overhead associated with RPC parameters has been reduced by eliminating some redundant
temporaries. Any call that passes large records, object types, or collections (including PL/SQL
index-by tables) will benefit from this optimization. This performance improvement is applicable
to server-to-server, as well as client-server RPC calls.

•= RETURNING INTO Clause Execution Improvement

Runtime code used for executing the RETURNING INTO clause of SQL DML statements was
tuned to reduce overhead. Applications that execute SQL will benefit from this enhancement.

FEATURES FOR APPLICATION DEVELOPMENT

Several features have been added for debugging and analysis, ease-of-use, and facilitation of
application development.

Debugging

In Oracle8i, PL/SQL now provides a DBMS_DEBUG API. This is a low-level API for the use of
third-party tools vendors. It can be used for providing debuggers to PL/SQL developers.
The API has several advanced debugging features, such as stop-on-exception, etc.
Several debuggers are already available using this API. For example, Oracle® Procedure Builder is an
excellent advanced client-server debugger that can transparently debug your Oracle Developer and
database applications. A simple debugger, written completely in Java, can be downloaded for free
from the PL/SQL web page (see Contact Information at the end of this paper). Third party tool
vendors, such as SQL Station from Platinum Technologies, SQL Navigator from Quest, and
Xpediter/SQL for Oracle from Compuware, also provide excellent debuggers.

Oracle8i PL/SQL — New Features and Future Directions 8


March 1999
Code Coverage

Oracle8i PL/SQL provides APIs that support PL/SQL code coverage, thereby extending the Probe
family of APIs. The APIs allow tool vendors and the Oracle Tools group to either develop a
stand-alone coverage tool, or embed a tool in an integrated development environment. Application
developers can use the PL/SQL code coverage data to measure the adequacy of their test suites, and to
focus their incremental testing efforts more efficiently.

Tracing

A DBMS_TRACE API has been provided, so that customers can trace programs by function, or by
exception. This feature should be very useful for debugging complex PL/SQL application bugs, when
a debugger is not easily available.

Profiling

See the Performance and Analysis Features section.

“ORA-06502: Numeric or Value Error” Message Improved

This error message has been improved. It now states the reason (in most cases) why the error
occurred. This should help customers find problems in their code much more easily.

Ease-of-Use Enhancements

Oracle has introduced several enhancements that simplify application development.

Package Body Size Limit Increased

Prior to Oracle8i PL/SQL, large package bodies failed to compile, due to an internal compiler limit
that required developers to decompose packages into smaller “units,” and solve the problem. In
Oracle8i, this is no longer needed, because the compiler limit has now been substantially increased,
allowing large package bodies to be compiled.

Oracle8i PL/SQL — New Features and Future Directions 9


March 1999
Purity

Prior to Oracle8i, if a user wanted to use a subprogram (i.e., functions and procedures), its purity
level (i.e., whether they read/write database/package state) had to be specified. This was done with
the RESTRICT_REFERENCES pragma. This qualification was necessary in the scenarios
shown below:

•= Calling a function from a query or DML statement

•= Parallelizing a query or DML statement that calls a function

•= Creating a snapshot with fast refresh

The compiler used this purity information, combined with additional computed information,
to determine whether or not it was safe to perform these operations. This pragma was often overly
restrictive, and disallowed several legitimate operations at compile-time. Oracle8i simplifies the
purity model. It is no longer necessary to supply this pragma to get compile-time checking.
Instead, illegal cases are flagged at runtime. In addition, the user still has the option of supplying
the pragma, in order to get compile-time checking of the bodies of these subprograms. This
approach is more flexible and easy-to-use than the available alternative in previous releases.

External Procedure Callbacks Using Pro*C

External Procedures now support Pro*C, to callback into the database, and is substantially easier to
use than Oracle Call Interface to program callbacks.

SQL Queries on a PL/SQL Table or Collection

In releases prior to Oracle8i PL/SQL Release 8.1, queries may be performed only against database
tables. Starting with Oracle8i PL/SQL Release 8.1, Oracle provides support for SQL queries on a
PL/SQL nested table or variable array variable. Users can now specify a PL/SQL variable, or
parameter of a PL/SQL nested table or variable array type, in the FROM clause of a SQL query, using
the TABLE() operator. This feature provides a powerful way of querying dynamically created
in-memory data.

Oracle8i PL/SQL — New Features and Future Directions 10


March 1999
Miscellaneous

•= Improved Interoperability — An Oracle 7 or Oracle8 server (or Developer /2000 product


™ ™ ™

containing PL/SQL 2.3 or 8.0) can remotely call a schema-level (as opposed to a package) stored
procedure or function in an Oracle8i database, even if the procedure or function body has new
Oracle8i features.

•= New Built-In Operators — Two new operators have been added to the package Standard. The
SYS_GUID built-in returns a globally unique identifier. The CONTEXT built-in was provided for
application security capabilities (see the Security documentation for further details).

NEW APPLICATION DEVELOPMENT FEATURES

Oracle8i includes new features that provide substantial benefits, and have been added for solving
specific application problems.

Autonomous Transactions

An autonomous transaction lets you step out of the context of the calling application’s transaction,
and perform SQL operations. These transaction semantics enable you to commit or rollback these
operations independent of the context of the calling application, and return to the calling transaction
to continue with the calling transaction.

Thus, autonomous transactions help create reusable application sub-components that perform
specialized transactional operations. These operations are independent of the calling application’s
transaction state, or the result of the called transaction.

Developers can benefit significantly from this feature, for operations such as error and audit logging.
Regardless of the state of the calling transaction, packages can be executed that will perform some
cataloging operations, and return control back to the caller, without having to take into account the
transaction state of the caller. Previously, this functionality had to be implemented using
DBMS_PIPE, which would callout to a C function that would perform the cataloging in a separate
session and transaction.

Oracle8i PL/SQL — New Features and Future Directions 11


March 1999
Native Dynamic SQL

Prior to Oracle8i, dynamic SQL statements in PL/SQL could only be executed using the DBMS_SQL
package interface. Native Dynamic SQL is a new dynamic SQL interface that is easier to use and
substantially faster than DBMS_SQL, allowing users to write much more compact code. Native
Dynamic SQL in PL/SQL provides the ability to dynamically execute SQL statements whose
complete text is not known until execution time. These dynamic statements include:

•= Data Manipulation Language (DML) Statements (Including Queries)

•= PL/SQL Anonymous Blocks

•= Data Definition Language (DDL) Statements

•= Transaction Control Statements

•= Session Control Statements (with Restrictions)

Current users of the DBMS_SQL package will immediately be able to see the ease-of-use benefits of
Native Dynamic SQL in the example shown on the following page:

Oracle8i PL/SQL — New Features and Future Directions 12


March 1999
Before Oracle8i: In Oracle8i with Native Dynamic SQL:
Dynamic SQL using DBMS_SQL. Dynamic SQL is now much easier and faster.

Rem Rem
Rem DML Example in DBMS_SQL Rem DML Example in Native Dynamic
Rem SQL
procedure insert_into_table Rem
(table_name varchar2, procedure insert_into_table
deptnumber number, deptname (table_name varchar2,
varchar2, location varchar2) is deptnumber number, deptname
cur_hdl integer; varchar2, location varchar2) is
stmt_str varchar2(200); stmt_str varchar2(200);
rows_processed binary_integer; begin
begin
stmt_str := 'insert into ' || stmt_str := 'insert into ' ||
table_name || ' values (:deptno, table_name || ' values (:deptno,
:dname, :dname,
:loc)'; :loc)';

-- open cursor EXECUTE IMMEDIATE stmt_str


cur_hdl := USING
dbms_sql.open_cursor; deptnumber, deptname, location;
end;
-- parse cursor
dbms_sql.parse(cur_hdl,
stmt_str, dbms_sql.native);

-- supply binds
dbms_sql.bind_variable(cur_hdl,
':deptno', deptnumber);
dbms_sql.bind_variable(cur_hdl,
':dname', deptname);
dbms_sql.bind_variable(cur_hdl,
':loc', location);

-- execute cursor
rows_processed :=
dbms_sql.execute(cur_hdl);

-- close cursor
dbms_sql.close_cursor(cur_hdl);
end;

Also, Native Dynamic SQL provides significant performance improvements (30-60 percent in our
benchmarks) over DBMS_SQL.

Oracle8i PL/SQL — New Features and Future Directions 13


March 1999
Invoker’s Rights

Invoker’s rights is a critical feature that substantially enhances code reuse. An invoker’s rights
program inherits the privileges and name resolution schema (the context) of the user calling the
program (the invoker). In contrast, a definer’s rights program, executes in the context of the user
that owns the procedure (the definer). This was the only option in previous releases, and is the
default option in Oracle8i.

Invoker’s rights is very useful for installing a generic software component that executes DDL or DML
on behalf of an invoking user. Since an invoker’s rights component automatically inherits its
invoker’s context, a single copy of the component can be installed and invoked by
multiple users.

Objects and Extensibility Enhancements

In addition to invoker’s rights and several performance improvements, the following enhancements
are available for objects and extensibility customers:

•= User-Defined Operators  In Oracle8i, users can define schema-level operators, and bind them to
PL/SQL functions. These operators can subsequently be used in SQL statements, wherever a SQL
built-in operator is allowed. Furthermore, an operator can optionally be supported by one or more
user-defined index types. This means that an index of this index type can be used in efficiently
evaluating these operators. This feature is very important for specialized datatype developers. For
®
example, Oracle's ConText specialized datatype has implemented CONTAINS as a user-defined
operator.

•= Static Methods  Static methods are methods that do not have SELF as a parameter. These are very
useful in applications, as static methods that logically belong to the object type, but do not operate
on the SELF parameter, can now be packaged in the object type itself.

•= Objects/Collections As Parameters To External Procedures  Object types and collections can now be
passed as parameters to external procedures. In the external procedure, standard Oracle Call
Interface calls can be used to operate on these types.

Oracle8i PL/SQL — New Features and Future Directions 14


March 1999
=
PL/SQL AND THE INTERNET

Today, dynamic content publishing is the dominant way of publishing information on the Internet,
and is quickly replacing static HTML pages. PL/SQL programmers can use the following capabilities
for dynamic web pages:

•= Using the Oracle® Application Server’s PL/SQL cartridge, users can easily write PL/SQL stored
procedures that publish dynamic information from the database, via the HTP and HTF packages in
HTML.

•= The UTL_HTTP package can be used for making HTTP requests from a stored
PL/SQL procedure.

•= Furthermore, Oracle Developer and Web Forms/Reports provide a very simple and automated
facility with which to migrate fat client PL/SQL applications to a thin client environment.

Oracle plans to further enhance these capabilities and provide inherent web/HTTP/HTML
capabilities in the database server, to add substantial value for our large customer community.

JAVA AND PL/SQL IN THE DATABASE SERVER

Java and PL/SQL seamlessly inter-operate and complement each other in the database.
Oracle plans to provide strong support for Java in all tiers. To this end, Oracle8i supports Java
stored procedures with an included Java Virtual Machine that executes in the server.

We believe that Java and PL/SQL will coexist as major languages in the server. PL/SQL will be the
choice for SQL programmers, because of its tight integration with Oracle’s SQL.
Java, on the other hand, has tremendous momentum, and can serve as the language for application
development in the server. Both languages will be strongly enhanced, so our customers can choose
the language best suited to their needs.

Consistent with our theme of "language transparency," Oracle is addressing Java and PL/SQL
interoperability in two ways:

•= Application Level Interoperability  PL/SQL and SQL can call Java methods, by registering the
callspecs for the Java class. Java can also call PL/SQL and SQL, via either JDBC or SQLJ.
In the future, Oracle plans to allow PL/SQL and Java stored procedures in the server to be debugged
transparently.

•= Shared Services Between the Java and PL/SQL Execution Engines  Within the server, the Java Virtual
Machine and the PL/SQL engine already share a number of common services,
to provide users with optimal performance and scalability.

Oracle8i PL/SQL — New Features and Future Directions 15


March 1999
CONCLUSION AND FUTURE DIRECTIONS

PL/SQL’s inherent strengths are inter-operation with SQL, and the power to shape the language for
customer-focused features. Oracle intends to build on these strengths, and work with our large
customer base to continue enhancing our PL/SQL product along the following dimensions:

•= Performance  Oracle plans to aggressively improve performance. For example, we are considering
compiling PL/SQL to C (and subsequently to machine code), which will transparently boost the
performance of all PL/SQL applications, by avoiding the interpreter overhead. Oracle also plans to
significantly optimize the runtime engine. This would allow for automatically self-tuned
applications and performance hints at compile time, to help customers manually tune their
applications. Oracle plans to enhance the profiler, so that customers can find bottlenecks
more easily.

•= Closer Integration Between PL/SQL and SQL  Oracle plans to integrate SQL and PL/SQL even more
closely at every level, from syntax and semantics for enhanced ease-of-use, to the internal levels, for
significantly enhanced performance.

•= Ease-of-Use Language Features  Oracle proactively meets with customers, to understand their
business problems, and provides easy-to-use features for solving their problems (i.e., native dynamic
SQL and autonomous transactions in Oracle8i)

•= Customer-Based Features  Oracle will continue seeking and addressing top customer enhancement
requests, enabling customers to build robust, powerful solutions. Oracle is also investigating
important business segments (i.e., Data Warehousing), for potential performance and ease-of-use
improvements.

•= PL/SQL and the Internet  Oracle will continue building enhancements, and making PL/SQL an
excellent language for scripting dynamic content from the server, by providing template support in
the database server. Oracle is also investigating potential synergy with XML.

•= PL/SQL and Java  Oracle will continue to further simplify interoperability between PL/SQL and
Java in the server, by integrated debugging capabilities. Interoperability will be enhanced outside
the server by integrating Java and PL/SQL in Oracle Developer.

Thus, applications developed with PL/SQL today will perform and scale even better in the future.
Customers can continue to build PL/SQL applications, secure in the knowledge that PL/SQL will
continue to be strengthened as an enterprise-level application platform that is suited especially well
to database programming.

Oracle8i PL/SQL — New Features and Future Directions 16


March 1999
CONTACT INFORMATION

For more information and details on the above features in PL/SQL, visit our
web site at: http://www.oracle.com/st/products/features/plsql.html, or send us an email at
plsqlweb@us.oracle.com.

Oracle8i PL/SQL — New Features and Future Directions 17


March 1999
Oracle Corporation
World Headquarters
500 Oracle Parkway
Redwood Shores, CA 94065
U.S.A.

Worldwide Inquiries:
+1.650.506.7000
Fax +1.650.506.7200
http://www.oracle.com/

Copyright © Oracle Corporation 1999


All Rights Reserved

This document is provided for informational purposes only, and


the information herein is subject to change without notice.
Please report any errors herein to Oracle Corporation. Oracle
Corporation does not provide any warranties covering and
specifically disclaims any liability in connection with this
document.

Oracle and ConText are registered trademarks, and Oracle8i,


PL/SQL, Pro*C, Oracle7, Oracle8 and Oracle Developer are
trademarks of Oracle Corporation. All other company and
product names mentioned are used for identification purposes
only and may be trademarks of their respective owners.