Advantages of PL/SQL
Advantages of PL/SQL
This chapter introduces the main features of the PL/SQL language. It shows how PL/SQL meets the challenges of database programming, and how you can reuse techniques that you know from other programming languages. This chapter contains these topics: Advantages of PL/SQL Understanding the Main Features of PL/SQL PL/SQL Architecture
Advantages of PL/SQL
PL/SQL is a completely portable, high-performance transaction processing language that offers the following advantages: Tight Integration with SQL Better Performance Higher Productivity Full Portability Tight Security Access to Pre-defined Packages Support for Object-Oriented Programming Support for Developing Web Applications and Pages See Also: Additional information and code samples for PL/SQL on the Oracle Technology Network (OTN), at:
http://www.oracle.com/technology/tech/pl_sql/
Information for a specific topic on OTN, such as "PL/SQL best practices", by entering the appropriate phrase in the search field on the OTN main page at:
http://www.oracle.com/technology/
Advantages of PL/SQL
1-2 Oracle Database PL/SQL Users Guide and Reference
SQL is a programming technique that makes your applications more flexible and versatile. Your programs can build and process SQL data definition, data control, and session control statements at run time, without knowing details such as table names and WHERE clauses in advance. For information on the use of static SQL with PL/SQL, see Chapter 6, "Performing SQL Operations from PL/SQL". For information on the use of dynamic SQL, see Chapter 7, "Performing SQL Operations with Native Dynamic SQL". For additional information about dynamic SQL, see Oracle Database Application Developer's Guide - Fundamentals.
Better Performance
Without PL/SQL, Oracle must process SQL statements one at a time. Programs that issue many SQL statements require multiple calls to the database, resulting in significant network and performance overhead. With PL/SQL, an entire block of statements can be sent to Oracle at one time. This can drastically reduce network traffic between the database and an application. As Figure 11 shows, you can use PL/SQL blocks and subprograms to group SQL statements before sending them to the database for execution. PL/SQL also has language features to further speed up SQL statements that are issued inside a loop. PL/SQL stored procedures are compiled once and stored in executable form, so procedure calls are efficient. Because stored procedures execute in the database server, a single call over the network can start a large job. This division of work reduces network traffic and improves response times. Stored procedures are cached and shared among users, which lowers memory requirements and invocation overhead. Advantages of PL/SQL
Overview of PL/SQL 1-3 Figure 11 PL/SQL Boosts Performance
Higher Productivity
PL/SQL lets you write very compact code for manipulating data. In the same way that scripting languages such as Perl can read, transform, and write data from files, PL/SQL can query, transform, and update data in a database. PL/SQL saves time on design and debugging by offering a full range of software-engineering features, such as exception handling, encapsulation, data hiding, and object-oriented datatypes. PL/SQL extends tools such as Oracle Forms. With PL/SQL in these tools, you can use familiar language constructs to build applications. For example, you can use an entire PL/SQL block in an Oracle Forms trigger, instead of multiple trigger steps, macros, or user exits. PL/SQL is the same in all environments. After you learn PL/SQL with one Oracle tool, you can transfer your knowledge to other tools.
Full Portability
Applications written in PL/SQL can run on any operating system and platform where the Oracle database runs. With PL/SQL, you can write portable program libraries and reuse them in different environments.
Tight Security
PL/SQL stored procedures move application code from the client to the server, where you can protect it from tampering, hide the internal details, and restrict who has access. For example, you can grant users access to a procedure that updates a table, but not grant them access to the table itself or to the text of the UPDATE statement. Triggers written in PL/SQL can control or record changes to data, making sure that all changes obey your business rules. For information on wrapping, or hiding, the source of a PL/SQL unit, see Appendix A, "Obfuscating PL/SQL Source Code".
SQL IF ... THEN SQL ELSE SQL END IF;
SQL
RPC
SQL SQL SQL SQL
Application Application Application Other DBMSs Oracle Database with PL/SQL Oracle Database with PL/SQL and Stored Procedures