Chapter 13. Miscellaneous Datatypes

In this chapter, we’ll explore all the native PL/SQL datatypes that we haven’t yet covered. These include the BOOLEAN , RAW, and UROWID/ROWID types, as well as the LOB (large object) family of types. We’ll also discuss some useful, predefined object types, including XMLType, which enables you to store XML data in a database column, and the Any types, which allow you to store, well, just about anything.

The BOOLEAN Datatype

Boolean values and variables are very useful in PL/SQL. Because a Boolean variable can only be TRUE, FALSE, or NULL, you can use that variable to explain what is happening in your code. With Booleans you can write code that is easily readable because it is more English-like. You can replace a complicated Boolean expression involving many different variables and tests with a single Boolean variable that directly expresses the intention and meaning of the text.

Here is an example of an IF statement with a single Boolean variable (or function—you really can’t tell the difference just by looking at this short bit of code):

    IF report_requested
       print_report (report_id);
    END IF;

The beauty of this technique is that it not only makes your code a bit more self-documenting, it also has the potential to insulate your code from future change. For example, consider the human interface that needs to precede the previous code fragment. How do we know that a report was requested? Perhaps we ask the user to answer a question with a Y or an ...

Get Oracle PL/SQL Programming, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.