Oracle8i Supplied Packages Reference Release 8.1.5 A68001-01 |
|
Oracle provides many packages with the Oracle server, either to extend the functionality of the database or to give PL/SQL access to SQL features. You may take advantage of the functionality provided by these packages when creating your application, or you may simply want to use these packages for ideas in creating your own stored procedures.
This chapter contains the following sections:
For detailed information on how to create your own packages, see Oracle8i Application Developer's Guide - Fundamentals.
See Also:
A package is an encapsulated collection of related program objects stored together in the database. Program objects are procedures, functions, variables, constants, cursors, and exceptions.
Packages have many advantages over stand-alone procedures and functions. For example, they:
Most Oracle supplied packaged are automatically installed when the database is created and the CATPROC
.SQL
script is run. For example, to create the DBMS_ALERT
package, the DBMSALRT
.SQL
and PRVTALRT
.PLB
scripts must be run when connected as the user SYS
. These scripts, however, are run automatically by the CATPROC
.SQL
script.
Certain packages are not installed automatically. Special installation instructions for these packages are documented in the individual chapters.
To call a PL/SQL function from SQL, you must either own the function or have EXECUTE
privileges on the function. To select from a view defined with a PL/SQL function, you must have SELECT
privileges on the view. No separate EXECUTE
privileges are needed to select from the view. Instructions on special requirements for packages are documented in the individual chapters.
There are two distinct steps to creating a new package:
CREATE
PACKAGE
statement.
You can declare program objects in the package specification. Such objects are called public objects. Public objects can be referenced outside the package, as well as by other objects in the package.
CREATE
PACKAGE
BODY
statement.
You can declare and define program objects in the package body:
For more information on creating new packages, see PL/SQL User's Guide and Reference and Oracle8i Application Developer's Guide - Fundamentals. For more information on storing and executing packages, see Oracle8i Concepts.
See Also:
The specification of a package declares the public types, variables, constants, and subprograms that are visible outside the immediate scope of the package. The body of a package defines the objects declared in the specification, as well as private objects that are not visible to applications outside the package.
Oracle stores the specification and body of a package separately in the database. Other schema objects that call or reference public program objects depend only on the package specification, not on the package body. This distinction allows you to change the definition of a program object in the package body without causing Oracle to invalidate other schema objects that call or reference the program object. Oracle invalidates dependent schema objects only if you change the declaration of the program object in the package specification.
The following example shows a package specification for a package named EMPLOYEE_MANAGEMENT
. The package contains one stored function and two stored procedures.
CREATE PACKAGE employee_management AS FUNCTION hire_emp (name VARCHAR2, job VARCHAR2, mgr NUMBER, hiredate DATE, sal NUMBER, comm NUMBER, deptno NUMBER) RETURN NUMBER; PROCEDURE fire_emp (emp_id NUMBER); PROCEDURE sal_raise (emp_id NUMBER, sal_incr NUMBER); END employee_management;
The body for this package defines the function and the procedures:
CREATE PACKAGE BODY employee_management AS FUNCTION hire_emp (name VARCHAR2, job VARCHAR2, mgr NUMBER, hiredate DATE, sal NUMBER, comm NUMBER, deptno NUMBER) RETURN NUMBER IS
The function accepts all arguments for the fields in the employee table except for the employee number. A value for this field is supplied by a sequence. The function returns the sequence number generated by the call to this function.
new_empno NUMBER(10); BEGIN SELECT emp_sequence.NEXTVAL INTO new_empno FROM dual; INSERT INTO emp VALUES (new_empno, name, job, mgr, hiredate, sal, comm, deptno); RETURN (new_empno); END hire_emp; PROCEDURE fire_emp(emp_id IN NUMBER) AS
The procedure deletes the employee with an employee number that corresponds to the argument emp_id
. If no employee is found, then an exception is raised.
BEGIN DELETE FROM emp WHERE empno = emp_id; IF SQL%NOTFOUND THEN raise_application_error(-20011, 'Invalid Employee Number: ' || TO_CHAR(emp_id)); END IF; END fire_emp; PROCEDURE sal_raise (emp_id IN NUMBER, sal_incr IN NUMBER) AS
The procedure accepts two arguments. Emp_id
is a number that corresponds to an employee number. Sal_incr
is the amount by which to increase the employee's salary.
BEGIN -- If employee exists, then update salary with increase. UPDATE emp SET sal = sal + sal_incr WHERE empno = emp_id; IF SQL%NOTFOUND THEN raise_application_error(-20011, 'Invalid Employee Number: ' || TO_CHAR(emp_id)); END IF; END sal_raise; END employee_management;
To reference the types, items, and subprograms declared in a package specification, use the dot notation. For example:
package_name.type_name package_name.item_name package_name.subprogram_name
This section lists each of the Oracle supplied server packages and indicates where they are described in more detail. These packages run as the invoking user, rather than the package owner. Unless otherwise noted, the packages are callable through public synonyms of the same name.
Package Name | Description | Documentation |
---|---|---|
Calendar (see Note #2 below) |
Provides calendar maintenance functions. |
|
DBMS_ALERT |
Provides support for the asynchronous notification of database events. |
|
DBMS_APPLICATION_INFO |
Lets you register an application name with the database for auditing or performance tracking purposes. |
|
DBMS_AQ |
Lets you add a message (of a predefined object type) onto a queue or to dequeue a message. |
|
DBMS_AQADM |
Lets you perform administrative functions on a queue or queue table for messages of a predefined object type. |
|
DBMS_DDL |
Provides access to some SQL DDL statements from stored procedures, and provides special administration operations not available as DDLs. |
|
DBMS_DEBUG |
A PL/SQL API to the PL/SQL debugger layer, Probe, in the Oracle server. |
|
DBMS_DEFER |
Provides the user interface to a replicated transactional deferred remote procedure call facility. Requires the Distributed Option. |
|
DBMS_DEFER_QUERY |
Permits querying the deferred remote procedure calls (RPC) queue data that is not exposed through views. Requires the Distributed Option. |
|
DMBS_DEFER_SYS |
Provides the system administrator interface to a replicated transactional deferred remote procedure call facility. Requires the Distributed Option. |
|
DBMS_DESCRIBE |
Describes the arguments of a stored procedure with full name translation and security checking. |
|
DBMS_DISTRIBUTED_TRUST_ADMIN |
Maintains the Trusted Database List, which is used to determine if a privileged database link from a particular server can be accepted. |
|
DBMS_HS |
Lets you create and modify objects in the Heterogeneous Services dictionary. |
|
DBMS_HS_PASSTHROUGH |
Lets you use Heterogeneous Services to send pass-through SQL statements to non-Oracle systems. |
|
DBMS_IOT |
Creates a table into which references to the chained rows for an Index Organized Table can be placed using the |
|
DBMS_JOB |
Lets you schedule administrative procedures that you want performed at periodic intervals; it is also the interface for the job queue. |
|
DBMS_LOB |
Provides general purpose routines for operations on Oracle Large Object ( |
|
DBMS_LOCK |
Lets you request, convert and release locks through Oracle Lock Management services. |
|
DBMS_LOGMNR |
Provides functions to initialize and run the log reader. |
|
DBMS_LOGMNR_D |
Queries the dictionary tables of the current database, and creates a text based file containing their contents. |
|
DBMS_OFFLINE_OG |
Provides public APIs for offline instantiation of master groups. |
|
DBMS_OFFLINE_SNAPSHOT |
Provides public APIs for offline instantiation of snapshots. |
|
DBMS_OLAP |
Provides procedures for summaries, dimensions, and query rewrites. |
|
DBMS_ORACLE_TRACE_AGENT |
Provides client callable interfaces to the Oracle TRACE instrumentation within the Oracle7 Server. |
|
DBMS_ORACLE_TRACE_USER |
Provides public access to the Oracle release 7 Server Oracle TRACE instrumentation for the calling user. |
|
DBMS_OUTPUT |
Accumulates information in a buffer so that it can be retrieved out later. |
|
DBMS_PCLXUTIL |
Provides intra-partition parallelism for creating partition-wise local indexes. |
|
DBMS_PIPE |
Provides a DBMS pipe service which enables messages to be sent between sessions. |
|
DBMS_PROFILER |
Provides a Probe Profiler API to profile existing PL/SQL applications and identify performance bottlenecks. |
|
DBMS_RANDOM |
Provides a built-in random number generator. |
|
DBMS_RECTIFIER_DIFF |
Provides APIs used to detect and resolve data inconsistencies between two replicated sites. |
|
DBMS_REFRESH |
Lets you create groups of snapshots that can be refreshed together to a transactionally consistent point in time. Requires the Distributed Option. |
|
DBMS_REPAIR |
Provides data corruption repair procedures. |
|
DBMS_REPCAT |
Provides routines to administer and update the replication catalog and environment. Requires the Replication Option. |
|
DBMS_REPCAT_ADMIN |
Lets you create users with the privileges needed by the symmetric replication facility. Requires the Replication Option. |
|
DBMS_REPCAT_INSTATIATE |
Instantiates deployment templates. Requires the Replication Option. |
|
DBMS_REPCAT_RGT |
Controls the maintenance and definition of refresh group templates. Requires the Replication Option. |
|
DBMS_REPUTIL |
Provides routines to generate shadow tables, triggers, and packages for table replication. |
|
DBMS_RESOURCE_MANAGER |
Maintains plans, consumer groups, and plan directives; it also provides semantics so that you may group together changes to the plan schema. |
|
DBMS_RESOURCE_MANAGER_PRIVS |
Maintains privileges associated with resource consumer groups. |
|
DBMS_RLS |
Provides row level security administrative interface. |
|
DBMS_ROWID |
Provides procedures to create |
|
DBMS_SESSION |
Provides access to SQL |
|
DBMS_SHARED_POOL |
Lets you keep objects in shared memory, so that they will not be aged out with the normal LRU mechanism. |
|
DBMS_SNAPSHOT
(synonym |
Lets you refresh snapshots that are not part of the same refresh group and purge logs. Requires the Distributed Option. |
|
DBMS_SPACE |
Provides segment space information not available through standard SQL. |
|
DBMS_SPACE_ADMIN |
Provides tablespace and segment space administration not available through the standard SQL. |
|
DBMS_SQL |
Lets you use dynamic SQL to access the database. |
|
DBMS_STANDARD |
Provides language facilities that help your application interact with Oracle. |
(see Note #1 below) |
DBMS_STATS |
Provides a mechanism for users to view and modify optimizer statistics gathered for database objects. |
|
DBMS_TRACE |
Provides routines to start and stop PL/SQL tracing. |
|
DBMS_TRANSACTION |
Provides access to SQL transaction statements from stored procedures and monitors transaction activities. |
|
DBMS_TTS |
Checks if the transportable set is self-contained. |
|
DBMS_UTILITY |
Provides various utility routines. |
|
DEBUG_EXTPROC |
Lets you debug external procedures on platforms with debuggers that can attach to a running process. |
|
OUTLN_PKG |
Provides the interface for procedures and functions associated with management of stored outlines. |
|
PLITBLM |
Handles index-table operations. |
(see Note #1 below) |
SDO_ADMIN (see Note #3 below) |
Provides functions implementing spatial index creation and maintenance for spatial objects. |
|
SDO_GEOM (see Note #3 below) |
Provides functions implementing geometric operations on spatial objects. |
|
SDO_MIGRATE (see Note #3 below) |
Provides functions for migrating spatial data from release 7.3.3 and 7.3.4 to 8.1.x. |
|
SDO_TUNE (see Note #3 below) |
Provides functions for selecting parameters that determine the behavior of the spatial indexing scheme used in the Spatial Cartridge. |
|
STANDARD |
Declares types, exceptions, and subprograms which are available automatically to every PL/SQL program. |
(see Note #1 below) |
TimeSeries (see Note #2 below) |
Provides functions that perform operations, such as extraction, retrieval, arithmetic, and aggregation, on time series data. |
|
TimeScale (see Note #2 below) |
Provides scaleup and scaledown functions. |
|
TSTools (see Note #2 below) |
Provides administrative tools procedures. |
|
UTL_COLL |
Enables PL/SQL programs to use collection locators to query and update. |
|
UTL_FILE |
Enables your PL/SQL programs to read and write operating system (OS) text files and provides a restricted version of standard OS stream file I/O. |
|
UTL_HTTP |
Enables HTTP callouts from PL/SQL and SQL to access data on the Internet or to call Oracle Web Server Cartridges. |
|
UTL_PG |
Provides functions for converting COBOL numeric data into Oracle numbers and Oracle numbers into COBOL numeric data. |
|
UTL_RAW |
Provides SQL functions for |
|
UTL_REF |
Enables a PL/SQL program to access an object by providing a reference to the object. |
|
Vir_Pkg (see Note #2 below) |
Provides analytical and conversion functions for Visual Information Retrieval. |
Oracle8i Visual Information Retrieval User's Guide and Reference |
The |
|
|
Time-Series, Image, Visual Information Retrieval, Audio, and Server-Managed Video Cartridge packages are installed in user ORDSYS without public synonyms. |
|
|
Spatial Cartridge packages are installed in user MDSYS with public synonyms. |
|
The packages listed in the remainder of this chapter are primarily documented in other Oracle books. This section lists the subprograms provided with each of these packages. Please refer to the above table for the cross-reference to the full documentation.
Subprogram | Description |
---|---|
POPULATE_INDEX |
Creates a spatial index on a table containing spatial data. |
UPDATE_INDEX |
Updates the spatial index for a given spatial object instance. |
Subprogram | Description |
---|---|
TO_81x |
Migrates spatial data from a 7.3.3 or 7.3.4 database to an 8.1.x database. |
Subprogram | Description |
---|---|
ESTIMATE_TILING_ LEVEL |
Suggests a value for the parameter that determines the resolution of the spatial index. |