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

12.4.4 The nclob Datatype

Use the NCLOB datatype to store large blocks of text represented using single-byte, fixed-width multibyte, or variable-width multibyte character sets inside the database. NCLOB is to CLOB what NVARCHAR2 is to VARCHAR2. Refer back to Chapter 8 for an introduction to character sets.

In Oracle8, variable-width character sets were not supported by NCLOB columns. Beginning with Oracle8i, NCLOBs do support variable-width characters.

An NCLOB variable contains a locator, which then points to the large block of character data. NCLOBs can be up to four gigabytes in size, and they participate fully in transactions. In other words, any changes you make to an NCLOB can be rolled back or committed along with other outstanding changes in your transaction. Like BLOB and CLOB locators, NCLOB locators cannot span transactions or sessions.

Here is an example of a declaration of an NCLOB variable:

DECLARE

directions NCLOB;

12.5 Working with loBs

The topic of working with large objects is, well, large, and we can't begin to cover every aspect of LOB programming in this chapter. What we can and will do, however, is provide you with a good introduction to the topic of LOB programming aimed especially at PL/SQL developers. We'll discuss some of the issues to be aware of and show examples of fundamental LOB operations. All of this, we hope, will provide you with a good foundation for your future LOB programming endeavors.

We will first introduce the different types of LOBs available to PL/SQL developers. Then it's time to learn about LOB locators and how to create LOBs. We will show you how to use DBMS_LOB to manipulate LOB contents and also introduce new, native syntax in Oracle9i that lets you work with LOBs using built-in functions like SUBSTR directly (albeit with an impact on performance, as is noted in that section).

Before getting into the meat of this section, please note that all LOB examples are based on the following table definition:

CREATE TABLE waterfalls (

falls_name VARCHAR2(80),

falls_photo BLOB,

falls_directions CLOB,

falls_description NCLOB,

falls_web_page BFILE);

This table contains rows about waterfalls located in Michigan's Upper Peninsula. Figure 12-2 shows the Dryer Hose, a falls frequented by ice-climbers, in its frozen state.

Figure 12-2. The Dryer Hose in Munising, Michigan

The table implements one column for each of the four LOB types. Photos consist of large amounts of binary data, so the falls_photo column is defined as a BLOB. Directions and descriptions are text, so those columns are CLOB and NCLOB, respectively. Normally, you'd use either CLOB or NCLOB for both, but we wanted to provide an example that made use of each LOB type. Finally, the master copy of the web page for each waterfall is stored in an HTML file outside the database. We use a BFILE column to point to that HTML file. We'll use these columns in our examples to demonstrate various facets of working with LOB data in PL/SQL programs.

In our discussion of large objects, we'll frequently use the acronym LOB to refer to CLOBs, BLOBs, NCLOBs, and BFILEs in general. We'll use specific type names only when discussing something specific to a type.

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