Oracle PL/SQL Programming, 2nd Edition

Oracle PL/SQL Programming, 2nd EditionSearch this book
Previous: I. Programming in PL/SQLChapter 1Next: 1.2 The Concept of Programming in Oracle Applications
 

1. Introduction to PL/SQL

Contents:
What Is PL/SQL?
The Concept of Programming in Oracle Applications
The Origins of PL/SQL
PL/SQL Versions
Advice for Oracle Programmers
A Few of My Favorite (PL/SQL) Things
Best Practices for PL/SQL Excellence

This chapter introduces PL/SQL, its origins, and its various versions. It also introduces you to what it means to be a PL/SQL programmer, and how PL/SQL programming differs from the kind of programming with which you may be familiar.

1.1 What Is PL/SQL?

PL/SQL stands for "Procedural Language extensions to SQL." PL/SQL is available primarily as an "enabling technology" within other software products; it does not exist as a standalone language. You can use PL/SQL in the Oracle relational database, in the Oracle Server, and in client-side application development tools, such as Oracle Forms. PL/SQL is closely integrated into the SQL language, yet it adds programming constructs that are not native to this standard relational database language. As you can see from the following code example, PL/SQL allows you to combine SQL statements with "standard" procedural constructs. This single program can either insert a company into or delete a company from the database. It relies on the IF statement (not a SQL statement) to determine which action to take:

PROCEDURE maintain_company
   (action_in IN VARCHAR2,
    id_in IN NUMBER,
    name_in IN VARCHAR2 := NULL)
IS
BEGIN
   IF action_in = 'DELETE'
   THEN
      DELETE FROM company WHERE company_id = id_in;

   ELSIF action_in = 'INSERT'
   THEN
      INSERT INTO company (company_id, name)
      VALUES (id_in, name_in);
   END IF;
END;

PL/SQL is an unusual -- and an unusually powerful -- programming language. You can write programs that look just like traditional 3GL modules, but you can also include calls to SQL statements, manipulate data through cursors, and take advantage of some of the newest developments in programming languages. PL/SQL supports packages which allow you to perform object-oriented design. PL/SQL provides a powerful mechanism for trapping and, with exception handlers, resolving errors. The tight integration of PL/SQL with SQL provides developers with the best of both worlds -- declarative and procedural logic.

Figure 1.1 shows how PL/SQL fits within the client-server architecture of Oracle-based applications. It shows both an Oracle Forms client and a non-Oracle tool client, both executing against an Oracle Server database. Notice that the Oracle Forms client makes use of two versions of PL/SQL:

The third-party tool executes calls to stored programs, which are then run on the server.

Figure 1.1: PL/SQL within the Oracle client-server architecture

Figure 1.1

Because PL/SQL is used both in the database (for stored procedures and database triggers) and in the application code (to implement logic within a form, for example), you can leverage the same programming language for both client-side and server-side development. You can even move programs from one component of the configuration to another.[1] For example, you might decide that a function which was originally coded for a single screen could be shared by all of the modules in an application. To make this happen, you simply move that function from the client-side screen component to the server-side database environment. You have to change neither the PL/SQL code nor any of the programs that call that function.

[1] As long as there are no conflicts between different versions of PL/SQL.

Of course, as an underlying technology in the Oracle constellation of products, PL/SQL is just one element of the total programming experience. In fact, building an Oracle-based application requires a combination of technology and techniques, as you'll see in the next section.


Previous: I. Programming in PL/SQLOracle PL/SQL Programming, 2nd EditionNext: 1.2 The Concept of Programming in Oracle Applications
I. Programming in PL/SQLBook Index1.2 The Concept of Programming in Oracle Applications

The Oracle Library Navigation

Copyright (c) 2000 O'Reilly & Associates. All rights reserved.

Library Home Oracle PL/SQL Programming, 2nd. Ed. Guide to Oracle 8i Features Oracle Built-in Packages Advanced PL/SQL Programming with Packages Oracle Web Applications Oracle PL/SQL Language Pocket Reference Oracle PL/SQL Built-ins Pocket Reference