Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Programming PL SQL.doc
Скачиваний:
3
Добавлен:
01.07.2025
Размер:
5 Мб
Скачать
☆

2.4.4 Pl/sql Server Pages

Although the PL/SQL Server Pages (PSP) environment is proprietary to Oracle, I thought I would mention it because it's a quick way to get a web page up and running. PSP is another precompiler technology; it gives you the ability to embed PL/SQL into HTML pages.

/* File on web: favorite_plsql_book.psp */

<%@ page language="PL/SQL" %>

<%@ plsql procedure="favorite_plsql_book" %>

<HTML>

<HEAD>

<TITLE>My favorite book about PL/SQL</TITLE>

</HEAD>

<BODY>

<%= booktitle( '0-596-00180-0') %>

</BODY>

</HTML>

That <%= %> line means "process this as PL/SQL and return the result to the page." When properly installed on a web server connected to an Oracle database, this page will display as in Figure 2-7.

Figure 2-7. Output from a pl/sql Server Page

I'm rather fond of PL/SQL Server Pages as a good way to put together data-driven web sites fairly quickly.

For more information about PL/SQL Server Pages, see Learning Oracle PL/SQL by the authors of the book you're reading now.

2.5 And What Else?

We've seen how to use PL/SQL in SQL*Plus and in a number of other common environments and programming languages. There are still more places you can use PL/SQL:

  • Embedded in COBOL or FORTRAN and processed with Oracle's precompiler

  • Called from Visual Basic, using some flavor of ODBC

  • Called from the Ada programming language, via a technology called SQL*Module

  • Executed automatically, as triggers on events in the Oracle database such as table updates

  • Scheduled to execute on a recurring basis inside the Oracle database, via the DBMS_JOB built-in package

We'll take a look at some of these approaches in upcoming chapters.

Chapter 3. Language Fundamentals

Every language—whether human or computer—has a syntax, a vocabulary, and a character set. In order to communicate within that language, you have to learn the rules that govern its usage. Many of us are wary of learning a new computer language. Change is often scary, but in general, programming languages are very simple tongues, and PL/SQL is a relatively simple programming language. The difficulty of conversing in languages based on bytes is not with the language itself, but with the compiler or computer with which we are having the discussion. Compilers are, for the most part, rather dull-witted. They are not creative, sentient beings. They are not capable of original thought. Their vocabulary is severely limited. Compilers just happen to think their dull thoughts very, very rapidly—and very inflexibly.

If I hear someone ask "gottabuck?", I can readily interpret that sentence and decide how to respond. On the other hand, if I instruct PL/SQL to "gimme the next half-dozen records," I will not get very far in my application. To use the PL/SQL language, you must dot your i's and cross your t's—syntactically speaking. So, this chapter covers the fundamental language rules that will help you converse with the PL/SQL compiler—the PL/SQL block structure, character set, lexical units, and PRAGMA keyword.

3.1 Pl/sql Block Structure

Virtually all programming languages give you a way to organize logically related elements into programming units. In PL/SQL, the fundamental unit of organization is the block, which is at the core of two key language concepts.

Modularization

The PL/SQL block is the basic unit of code from which you will build modules, such as procedures and functions, which in turn comprise applications. As the lowest organizational unit, well-designed blocks are fundamental to achieving code that other programmers can easily use and maintain.

Scope

The block provides a scope or context for logically related objects. In the block, you group together declarations and executable statements that belong together.

You can create anonymous blocks (blocks of code that have no name) and named blocks, which are procedures and functions. Furthermore, you can build packages in PL/SQL that group together multiple procedures and functions.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]