12.07.2015 Views

Oracle SQL Developer

Oracle SQL Developer

Oracle SQL Developer

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Overview of Packages and SubprogramsThis topic includes the following topics:■■Stored SubprogramsPackages8.1.1 Stored Subprograms8.1.2 PackagesSee Also: PL/<strong>SQL</strong> User's Guide and Reference to learn about PL/<strong>SQL</strong>code and program units.Subprograms, which are either functions or procedures, can be compiled and stored inan <strong>Oracle</strong> database, ready to be executed. Once compiled, it is a schema object knownas a stored procedure or stored function, which can be referenced by any number ofapplications connected to that database.The <strong>SQL</strong> CREATE PROCEDURE statement is used to create stored procedures that arestored in the database. The <strong>SQL</strong> CREATE FUNCTION statement is used to create storedfunctions that are stored in an <strong>Oracle</strong> database.See Also:■■<strong>Oracle</strong> Database <strong>SQL</strong> Reference for information on CREATEPROCEDURE.<strong>Oracle</strong> Database <strong>SQL</strong> Reference for information on CREATEFUNCTION.Subprograms are stored in a compact compiled form. When called, they are loadedand processed immediately. Subprograms take advantage of shared memory, so thatonly one copy of a subprogram is loaded into memory for execution by multiple users.See Also: <strong>Oracle</strong> Database Express Edition 2 Day DBA Guide forinformation on managing memory with <strong>Oracle</strong> DatabaseStored subprograms defined within a package are known as packaged subprograms.Those defined independently are called stored or standalone subprograms.Subprograms nested inside other subprograms or within a PL/<strong>SQL</strong> block are knownas local subprograms, which cannot be referenced by other applications and exist onlyinside the enclosing block.Stored subprograms are the key to modular, reusable PL/<strong>SQL</strong> code. Wherever youmight use a JAR file in Java, a module in Perl, a shared library in C++, or a DLL inVisual Basic, you should use PL/<strong>SQL</strong> stored procedures, stored functions, andpackages.You can call stored subprograms from a database trigger, another stored subprogram,or interactively from <strong>SQL</strong>*Plus. You can also configure a web server so that the HTMLfor a web page is generated by a stored subprogram, making it simple to provide aweb interface for data entry and report generation.A package is a schema object that groups logically related PL/<strong>SQL</strong> types, variables,and subprograms. Packages usually have two parts, a specification (spec) and a body;sometimes the body is unnecessary. The specification is the interface to the package. Itdeclares the types, variables, constants, exceptions, cursors, and subprograms that canbe referenced from outside the package. The body defines the queries for the cursorsand the code for the subprograms.8-2 <strong>SQL</strong> <strong>Developer</strong> Online Help

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!