PL/SQL   «Prev  Next»

Lesson 2Introducing LOBs
ObjectiveDescribe the types of LOBs in Oracle 26ai.

Types of Oracle LOBs

A scanned contract, an editable report, and a file maintained by another application may all be large, but they do not represent the same storage requirement. One application needs to preserve original bytes, another needs to process characters, and a third needs to reference content that remains outside the database. Choosing a large object type starts with those differences.

Oracle AI Database 26ai supports four familiar LOB types: BLOB, CLOB, NCLOB, and BFILE. This lesson compares their content semantics, storage locations, and operational consequences. By the end, you should be able to explain why a particular type fits a requirement, rather than choosing a type simply because a value is described as a large file.

Internal and external LOBs

BLOB, CLOB, and NCLOB are internal LOB types. When their values are stored persistently in table rows, the database manages the content. BFILE provides a reference to an external operating-system file whose contents remain outside database tablespaces. A tablespace is a logical database storage unit; an external directory is a different kind of location.

The distinction concerns the content, not merely the presence of a column. A BFILE column is part of a database table, but the referenced file's bytes are not thereby copied into that table. Conversely, an internal LOB can have its content stored outside the table row while still remaining within database storage.

Comparing Oracle LOB types
TypeContentLocationExample requirement
BLOBBinary bytesInternal LOBRetain an original PDF or photograph
CLOBText in the database character setInternal LOBStore an editable report body
NCLOBText in the national character setInternal LOBMeet a national-character-set requirement
BFILERead-only access through Oracle to file bytesExternal server-side fileReference externally managed source material

Use this table as a starting point. The following sections explain the questions behind each choice, including what the datatype does not decide for the application.

BLOB: preserving binary content

A binary large object, or BLOB, represents bytes without interpreting them as characters. Typical examples include a photograph, an audio recording, and a PDF. Although a PDF may display readable text, its file representation contains more than a plain character string. Retaining that representation is a binary-storage requirement.

Suppose a contract application must preserve the exact file supplied by a customer. A BLOB can hold that file while ordinary columns hold its identifier, title, media type, and upload date. Those descriptive values help the application find and present the document without opening its contents. The document format remains the responsibility of the software that interprets the bytes.

Binary storage does not automatically recognize signatures, extract paragraphs, or establish that a file is valid. If the application also needs extracted text, that is another representation with its own processing steps. Storing the original and the extracted text separately can make their different purposes clear. The extracted version should not silently replace the original when preserving the upload matters.

A BLOB can contain text encoded as bytes, but the application must know how to interpret that encoding. Use this possibility deliberately. It does not make a BLOB interchangeable with a character LOB, whose operations have character semantics. Ask whether the requirement is to preserve a file representation or to work with the text itself.

CLOB: text in the database character set

A character large object, or CLOB, represents text using the database character set. It is appropriate for substantial textual content such as report bodies, descriptions, and transcribed documents. Unlike the legacy description of CLOBs as single-byte-only data, a CLOB can represent multilingual text when the database character set supports the required characters.

Consider an application in which editors revise the body of a technical report. The report body is character data; its title and identifier are separate metadata. A CLOB can represent the body while the application applies its editing rules. Choosing CLOB does not by itself supply revision history, document approval, or collaborative editing. Those features still require an application design.

The database character set is therefore part of the choice. Determine which characters the application must preserve and whether the database and client configuration support them. Do not infer character support from the fact that a document looks correct in one editor. The complete path from input through storage to retrieval must represent the intended text.

Keep small descriptive values in suitable ordinary columns when their requirements fit those types. A document title does not need a CLOB simply because the document body uses one. Separating title from body also gives the application a clear basis for listing and identifying documents without treating their entire contents as labels.

NCLOB: text in the national character set

A national character large object, or NCLOB, represents text using the national character set. The key comparison with CLOB is the character-set relationship, not whether the text is important, international, or particularly large. Evaluate the actual database and application requirements before selecting between the two.

For example, a system may have an established requirement to process certain text through national-character types. NCLOB can fit that requirement for large text. In another system, the database character set may already support all required languages, and a CLOB may meet the same document-content need. The label “multilingual” alone does not determine the answer.

This course also examines object-relational structures, so one restriction matters: an NCLOB can be a table column, but it cannot be an attribute of an Oracle object type. Oracle documents support for NCLOB parameters in object methods separately. A method parameter does not become a stored attribute merely because the method belongs to an object type.

Check that distinction before designing a document object. If the object needs a text attribute, verify which supported type and character-set arrangement meet the requirement. If NCLOB storage is necessary, consider an appropriate relational design instead of assuming that every table-column type can be used unchanged as an object attribute. The next lesson's table examples should be read with that boundary in mind.

BFILE: referencing an external file

A BFILE gives Oracle read-only byte-stream access to a file outside database tablespaces. The column stores a locator identifying the external file through a directory object and a filename. The content remains in the server-side file system. This is not a reference to an arbitrary document on the computer of someone viewing a web application.

The referenced file must be available when the application reads it. Database privileges and operating-system access both matter. Creating or storing a locator does not prove that the file currently exists, that the server can read it, or that another process will keep it at the same location.

BFILE access is read-only through Oracle's BFILE interfaces. An external application may still change the operating-system file. Updating a locator to identify another file changes the database reference, not the bytes of either file. Likewise, deleting a row containing a BFILE reference does not delete the external file.

Byte-stream access supports processing a file in portions. The presence of offset-based reads does not mean that an application cannot read successive portions in order. Avoid the old claim that BFILE supports random access but makes sequential reading impossible. What matters here is that the content is read externally rather than modified through the BFILE interface.

When external storage fits the requirement

Imagine that a separate publishing system maintains source files in an agreed server directory. A database application needs to associate those files with catalog records and read them as input to a processing task. BFILE may fit when the publishing system continues to own the files and the database does not need to modify their bytes.

Now change the requirement: the database application must retain its own authoritative copy even if the publishing system replaces or removes its source. A reference alone does not satisfy that requirement. Loading the content into an internal LOB changes the ownership arrangement by creating database-managed content. The choice follows the retention requirement rather than the filename extension.

For external files, agree on naming, availability, replacement, and recovery procedures. A database backup does not automatically back up the referenced bytes. Restoring a row with its locator will not reconstruct a missing file. The team responsible for the file system must coordinate recovery with the team responsible for the database metadata.

These responsibilities are relevant even when the files rarely change. A stable document can become unavailable because a directory is renamed, permissions change, or storage is moved. Treat the database reference and the external content as related resources with separate lifecycles.

Values and locators

The LOB value is the content; a locator is a database-managed reference used by supported interfaces to access that content. Do not treat a locator as an application memory address or a portable identifier to save and reuse in unrelated sessions. Its validity and permitted operations depend on the interface and database context.

For a document application, retain the document's ordinary business identifier as the way to locate the row again. Obtain the appropriate LOB reference when performing an operation. That separates the application's identity for the document from the access mechanism used for its current contents.

Locator rules also distinguish reading from writing. A locator associated with an earlier transaction cannot be reused for writes in a later transaction. Some reads remain possible across transaction boundaries in non-serializable transactions, while serializable transactions impose additional restrictions. Obtain an appropriate locator and required row lock within the modifying transaction rather than relying on a blanket assumption that every old locator remains writable.

Persistent and temporary LOBs

BLOB, CLOB, and NCLOB describe content types. Persistent and temporary describe a different aspect: how the LOB instance is used and retained. A persistent LOB belongs to a stored table row. A temporary LOB supports transient processing, such as constructing content before deciding whether to store a completed result.

For example, assembling a report and retaining the approved report are different stages of a workflow. The temporary working result is not automatically the permanent business record. The application must deliberately store the content and associate it with the correct metadata when that is required.

Persistent internal LOB changes participate in database transactions. Temporary LOBs have different lifetime and transaction behavior; do not assume that their contents follow the same rollback rules. Likewise, rolling back a database transaction does not reverse an external process's changes to BFILE bytes. Keep the specific kind of instance in view when discussing commit, rollback, and cleanup.

Storage implementation and capacity

SecureFiles and BasicFiles describe internal LOB storage implementations. They are not additional SQL content types alongside BLOB and CLOB. SecureFiles is Oracle's recommended modern mechanism, subject to the relevant configuration and tablespace requirements. An application still declares the appropriate content type.

Similarly, inline and out-of-line describe where internal content is placed relative to its table row. Out-of-line storage remains database storage. It does not require choosing BFILE. Keep these distinctions separate when reading storage clauses or discussing a schema with an administrator.

Do not use the legacy universal 4 GB statement as a modern capacity rule for internal LOBs. Their supported capacity depends on configuration and can be much larger. For an actual implementation, verify the server release, storage configuration, operating system where applicable, and access API. A maximum supported by one part of the system does not establish the limit of every client buffer or operation.

Parallel execution is also conditional. Oracle supports parallel operations involving LOBs in documented circumstances, so a blanket prohibition on all parallel DML and DDL is misleading. The operation, storage arrangement, partitioning, and other restrictions matter. Selecting a datatype in this lesson does not establish a parallel-execution plan or a performance guarantee.

A practical selection process

Use the following questions when reviewing a proposed large-object column. Start with the content and ownership requirements before considering storage tuning.

  1. What must be preserved? Decide whether the application needs original bytes, editable text, or access to an externally maintained file.
  2. Who owns the content? Decide whether the database must retain the content independently or whether another system controls its availability.
  3. Which character set applies? For text, compare the database and national character-set requirements rather than selecting by language labels alone.
  4. Which structure will contain it? Distinguish an ordinary table column from an object attribute, particularly when NCLOB is involved.
  5. What operations are required? Identify reading, replacement, partial modification, retention, and recovery expectations.

Document the reasoning in terms of those requirements. “Use BLOB because the application must retain the uploaded PDF bytes” explains more than “use a large field.” It also gives a future maintainer a way to assess whether a changed requirement calls for another representation.

Check your understanding

A contract system stores an uploaded scan and a corrected transcription. The scan preserves a binary file representation, so BLOB is a suitable candidate when the database should own it. The transcription is character data, so CLOB or NCLOB should be evaluated according to the character-set requirements. One business document can therefore have more than one useful stored representation.

A separate archive maintains files that the database only reads. BFILE is a candidate if that external ownership is intentional. If the archive can remove files while the application must retain them, reconsider whether a reference meets the requirement. The same filename can participate in two very different ownership designs.

Finally, an object type needs a large text attribute. Do not choose NCLOB solely because the text includes several languages. Verify the character-set requirement and the object-attribute restriction together. A technically valid column type does not automatically produce a valid object-type definition.

In the next lesson, Creating a Table Using a LOB Column, you will apply these distinctions to a table definition. Carry forward the content type, ownership decision, and character-set requirements so that the declaration follows a clear purpose.

Oracle documentation


SEMrush Software 2 SEMrush Banner 2