PL/SQL (Procedural Language/Structured Query Language) is Oracle Corporation's procedural language extension for SQL and the Oracle relational database. PL/SQL is available in Oracle Database TimesTen in-memory database and IBM DB2. Oracle Corporation usually extends PL/SQL functionality with each successive release of the Oracle Database.
PL/SQL includes procedural language elements such as conditions and loops. It allows declaration of constants and variables, procedures and functions, types and variables of those types, and triggers. It can handle exceptions (runtime errors). Arrays are supported involving the use of PL/SQL collections. Implementations from version 8 of Oracle Database onwards have included features associated with object-orientation. One can create PL/SQL units such as procedures, functions, packages, types, and triggers, which are stored in the database for reuse by applications that use any of the Oracle Database programmatic interfaces.
Procedure
Procedures are similar to functions, in that they are named program units that can be invoked repeatedly. The primary difference is that functions can be used in a SQL statement whereas procedures cannot. Another difference is that the procedure can return multiple values whereas a function should only return a single value.
The procedure begins with a mandatory heading part to hold the procedure name and optionally the procedure parameter list. Next are the declarative, executable and exception-handling parts, as in the PL/SQL Anonymous Block. Here is an example of a simple procedure.
CREATE PROCEDURE create_email_address ( -- Procedure heading part begins name1 VARCHAR2, name2 VARCHAR2, company VARCHAR2, email OUT VARCHAR2 ) -- Procedure heading part ends AS -- Declarative part begins (optional) error_message VARCHAR2(30) := 'Email address is too long.'; BEGIN -- Executable part begins (mandatory) email := name1 || '.' || name2 || '@' || company; EXCEPTION -- Exception-handling part begins (optional) WHEN VALUE_ERROR THEN DBMS_OUTPUT.PUT_LINE(error_message); END create_email_address;
Advantages of Stored Procedures
To help you build powerful database applications, stored
procedures provide several advantages including better performance, higher
productivity, ease of use, and increased scalability.
Stored procedures are compiled once and stored in executable form,
so procedure calls are quick and efficient. Executable code is automatically
cached and shared among users. This lowers memory requirements and invocation
overhead.
By grouping SQL statements, a stored procedure allows them to be
executed with a single call. This minimizes the use of slow networks, reduces
network traffic, and improves round-trip response time. OLTP applications, in
particular, benefit because result set processing eliminates network
bottlenecks.
Additionally, stored procedures enable you to take advantage of
the computing resources of the server. For example, you can move
computation-bound procedures from client to server, where they will execute
faster. Likewise, stored functions called from SQL statements enhance
performance by executing application logic within the server.
Stored procedures increase scalability by isolating application
processing on the server. In addition, automatic dependency tracking for stored
procedures aids the development of scalable applications.
The shared memory facilities of the Multi-Threaded Server (MTS)
enable Oracle8i to support more than 10,000 concurrent users on a
single node. For more scalability, you can use the Net8 Connection Manager to
multiplex Net8 connections.
Once it is validated, a stored procedure can be used with
confidence in any number of applications. If its definition changes, only the
procedure is affected, not the applications that call it. This simplifies
maintenance and enhancement. Also, maintaining a procedure on the server is
easier than maintaining copies on various client machines.
Within the RDBMS, Java conforms fully to the Java Language
Specification and furnishes all the advantages of a general-purpose,
object-oriented programming language. Also, like PL/SQL, Java provides full
access to Oracle data, so any procedure written in PL/SQL can be written in
Java.
PL/SQL stored procedures complement Java stored procedures.
Typically, SQL programmers who want procedural extensions favor PL/SQL, and
Java programmers who want easy access to Oracle data favor Java.
The RDBMS allows a high degree of interoperability between Java
and PL/SQL. Java applications can call PL/SQL stored procedures using an
embedded JDBC driver. Conversely, PL/SQL applications can call Java stored
procedures directly.
You can restrict access to Oracle data by allowing users to
manipulate the data only through stored procedures that execute with their
definer's privileges. For example, you can allow access to a procedure that
updates a database table, but deny access to the table itself.
With Oracle Advanced Replication, stored procedures can be
replicated (copied) from one Oracle8i database to another. This
feature makes them ideal for implementing a central set of business rules. Once
written, the stored procedures are replicated and distributed to work groups
and branch offices throughout the company. In this way, policies can be revised
on a central server rather than on individual servers.
7.Productivity and Ease of Use
By designing applications around a common set of stored procedures, you can avoid redundant coding and increase your productivity. Moreover, stored procedures let you extend the functionality of the RDBMS. For example, stored functions called from SQL statements enhance the power of SQL.
You can use the Java integrated development environment (IDE) of your choice to create stored procedures. Then, you can deploy them on any tier of the network architecture. Moreover, they can be called by standard Java interfaces such as JDBC, CORBA, and EJB and by programmatic interfaces and development tools such as SQLJ, the OCI, Pro*C/C++, and JDeveloper.
This broad access to stored procedures lets you share business logic across applications. For example, a stored procedure that implements a business rule can be called from various client-side applications, all of which can share that business rule. In addition, you can leverage the server's Java facilities while continuing to write applications for your favorite programmatic interface.
Comments
Post a Comment