Overloading Packaged Subprograms. Oracle Release 2 (9.2)
Реклама
Реклама
How Package STANDARD Defines the PL/SQL Environment
Overloading Packaged Subprograms
PL/SQL allows two or more packaged subprograms to have the same name. This option is useful when you want a subprogram to accept similar sets of parameters that have different datatypes. For example, the following package defines two procedures named journalize
:
CREATE PACKAGE journal_entries AS
...
PROCEDURE journalize (amount REAL, trans_date VARCHAR2);
PROCEDURE journalize (amount REAL, trans_date INT);
END journal_entries;
CREATE PACKAGE BODY journal_entries AS
...
PROCEDURE journalize (amount REAL, trans_date VARCHAR2) IS
BEGIN
INSERT INTO journal
VALUES (amount, TO_DATE(trans_date, ’DD-MON-YYYY’));
END journalize;
PROCEDURE journalize (amount REAL, trans_date INT) IS
BEGIN
INSERT INTO journal
VALUES (amount, TO_DATE(trans_date, ’J’));
END journalize;
END journal_entries;
The first procedure accepts trans_date
as a character string, while the second procedure accepts it as a number (the Julian day). Each procedure handles the data appropriately. For the rules that apply to overloaded subprograms, see
"Overloading Subprogram Names" on page 8-23.
How Package STANDARD Defines the PL/SQL Environment
A package named
STANDARD
defines the PL/SQL environment. The package spec globally declares types, exceptions, and subprograms, which are available automatically to PL/SQL programs. For example, package
STANDARD
declares function
ABS
, which returns the absolute value of its argument, as follows:
FUNCTION ABS (n NUMBER) RETURN NUMBER;
The contents of package
STANDARD
are directly visible to applications. You do not need to qualify references to its contents by prefixing the package name. For
PL/SQL Packages
9-15
Скачать
Реклама