O'Reilly logo

Learning Oracle PL/SQL by Steven Feuerstein, Bill Pribyl

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

2.3. Introduction to Program Structure

My son, now eight, is a Lego fanatic. While many of his new-fangled, special-purpose Lego components are in many ways different from the simple bricks I had as a child, the idea of constructing from parts is the same. I think humans find something comforting about assembling objects of similar size, shape, and function into useful artifacts. As a grown-up programmer I'm still, after a fashion, playing with blocks.

2.3.1. More About Blocks

In PL/SQL, there are only three types of blocks:

  • Anonymous blocks

  • Procedures

  • Functions

We've already seen a simple anonymous block—that is, one without a name—in the "hello, world" example. The other two types of blocks, procedures and functions, are similar but also include a header.

There are actually four possible components of a PL/SQL block:

  • The definition of its interface (that is, information such as its name that will be needed to invoke it later)

  • Some number of variables

  • A sequence of statements (which may include SQL statements) intended to solve some problem or perform some action

  • A way to recover from "issues"

These components are organized into sections inside the block, as illustrated in Figure 2-1.

Figure 2-1. Representation of a named PL/SQL block

Although there are places other than blocks where PL/SQL can exist, I'll introduce those in later chapters. The next two sections will give ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required