Skip Headers

PL/SQL Packages and Types Reference
10g Release 1 (10.1)

Part Number B10802-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Feedback

Go to previous page
Previous
Go to next page
Next
View PDF

45
DBMS_LOB

The DBMS_LOB package provides subprograms to operate on BLOBs, CLOBs, NCLOBs, BFILEs, and temporary LOBs. You can use DBMS_LOB to access and manipulation specific parts of a LOB or complete LOBs.

See Also:

Oracle Database Application Developer's Guide - Large Objects

This chapter contains the following topics:


Using DBMS_LOB


Overview

DBMS_LOB can read and modify BLOBs, CLOBs, and NCLOBs; it provides read-only operations for BFILEs. The bulk of the LOB operations are provided by this package.


Security Model

This package must be created under SYS. Operations provided by this package are performed under the current calling user, not under the package owner SYS.

Any DBMS_LOB subprogram called from an anonymous PL/SQL block is executed using the privileges of the current user. Any DBMS_LOB subprogram called from a stored procedure is executed using the privileges of the owner of the stored procedure.

When creating the procedure, users can set the AUTHID to indicate whether they want definer's rights or invoker's rights. For example:

CREATE PROCEDURE proc1 authid definer ...
 

or

CREATE PROCEDURE proc1 authid current_user ...
See Also:

For more information on AUTHID and privileges, see PL/SQL User's Guide and Reference

You can provide secure access to BFILEs using the DIRECTORY feature discussed in BFILENAME function in the Oracle Database Application Developer's Guide - Large Objects and the Oracle Database SQL Reference.

For information about the security model pertaining to temporary LOBs, see Operational Notes.


Constants

DBMS_LOB defines the following constants:

file_readonly CONSTANT BINARY_INTEGER := 0;
lob_readonly  CONSTANT BINARY_INTEGER := 0;
lob_readwrite CONSTANT BINARY_INTEGER := 1;
lobmaxsize    CONSTANT INTEGER        := 18446744073709551615;
call          CONSTANT PLS_INTEGER    := 12;
session       CONSTANT PLS_INTEGER    := 10;

Types

Parameters for the DBMS_LOB subprograms use these datatypes:

Table 45-1 DBMS_LOB Datatypes
Type Description
BLOB

A source or destination binary LOB.

RAW

A source or destination RAW buffer (used with BLOB).

CLOB

A source or destination character LOB (including NCLOB).

VARCHAR2

A source or destination character buffer (used with CLOB and NCLOB).

INTEGER

Specifies the size of a buffer or LOB, the offset into a LOB, or the amount to access.

BFILE

A large, binary object stored outside the database.

The DBMS_LOB package defines no special types. An NCLOB is a CLOB for holding fixed-width and varying-width, multibyte national character sets. The clause ANY_CS in the specification of DBMS_LOB subprograms for CLOBs enables the CLOB type to accept a CLOB or NCLOB locator variable as input.


Rules and Limits

General Rules and Limits

Rules and Limits Specific to External Files (BFILEs)

Maximum LOB Size

The maximum size of a LOB supported by the database is equal to the value of the db_block_size initialization parameter times the value 4294967295. This allows for a maximum LOB size ranging from 8 terabytes to 128 terabytes.

Maximum Buffer Size

The maximum buffer size, 32767 bytes, is represented by maxbufsize.


Operational Notes

All DBMS_LOB subprograms work based on LOB locators. For the successful completion of DBMS_LOB subprograms, you must provide an input locator that represents a LOB that already exists in the database tablespaces or external file system. See also Chapter 1 of Oracle Database Application Developer's Guide - Large Objects.

To use LOBs in your database, you must first use SQL data definition language (DDL) to define the tables that contain LOB columns.

Internal LOBs

To populate your table with internal LOBs after LOB columns are defined in a table, you use the SQL data manipulation language (DML) to initialize or populate the locators in the LOB columns.

External LOBs

For an external LOB (BFILE) to be represented by a LOB locator, you must:

Once you have completed these tasks, you can insert or update a row containing a LOB column using the given LOB locator.

After the LOBs are defined and created, you can then SELECT from a LOB locator into a local PL/SQL LOB variable and use this variable as an input parameter to DBMS_LOB for access to the LOB value.

For details on the different ways to do this, you must refer to the section of the Oracle Database Application Developer's Guide - Large Objects that describes Accessing External LOBs (BFILEs).

Temporary LOBs

The database supports the definition, creation, deletion, access, and update of temporary LOBs. Your temporary tablespace stores the temporary LOB data. Temporary LOBs are not permanently stored in the database. Their purpose is mainly to perform transformations on LOB data.

For temporary LOBs, you must use the OCI, PL/SQL, or another programmatic interface to create or manipulate them. Temporary LOBs can be either BLOBs, CLOBs, or NCLOBs.

A temporary LOB is empty when it is created. By default, all temporary LOBs are deleted at the end of the session in which they were created. If a process dies unexpectedly or if the database crashes, then temporary LOBs are deleted, and the space for temporary LOBs is freed.

There is also an interface to let you group temporary LOBs together into a logical bucket. The duration represents this logical store for temporary LOBs. Each temporary LOB can have separate storage characteristics, such as CACHE/ NOCACHE. There is a default store for every session into which temporary LOBs are placed if you don't specify a specific duration. Additionally, you are able to perform a free operation on durations, which causes all contents in a duration to be freed.

There is no support for consistent read (CR), undo, backup, parallel processing, or transaction management for temporary LOBs. Because CR and rollbacks are not supported for temporary LOBs, you must free the temporary LOB and start over again if you encounter an error.

Because CR, undo, and versions are not generated for temporary LOBs, there is potentially a performance impact if you assign multiple locators to the same temporary LOB. Semantically, each locator should have its own copy of the temporary LOB.

A copy of a temporary LOB is created if the user modifies the temporary LOB while another locator is also pointing to it. The locator on which a modification was performed now points to a new copy of the temporary LOB. Other locators no longer see the same data as the locator through which the modification was made. A deep copy was not incurred by permanent LOBs in these types of situations, because CR snapshots and version pages enable users to see their own versions of the LOB cheaply.

You can gain pseudo-REF semantics by using pointers to locators in OCI and by having multiple pointers to locators point to the same temporary LOB locator, if necessary. In PL/SQL, you must avoid using more than one locator for each temporary LOB. The temporary LOB locator can be passed by reference to other procedures.

Because temporary LOBs are not associated with any table schema, there are no meanings to the terms in-row and out-of-row temporary LOBs. Creation of a temporary LOB instance by a user causes the engine to create and return a locator to the LOB data. The PL/SQL DBMS_LOB package, PRO*C, OCI, and other programmatic interfaces operate on temporary LOBs through these locators just as they do for permanent LOBs.

There is no support for client side temporary LOBs. All temporary LOBs reside in the server.

Temporary LOBs do not support the EMPTY_BLOB or EMPTY_CLOB functions that are supported for permanent LOBs. The EMPTY_BLOB function specifies the fact that the LOB is initialized, but not populated with any data.

A temporary LOB instance can only be destroyed by using OCI or the DBMS_LOB package by using the appropriate FREETEMPORARY or OCIDurationEnd statement.

A temporary LOB instance can be accessed and modified using appropriate OCI and DBMS_LOB statements, just as for regular permanent internal LOBs. To make a temporary LOB permanent, you must explicitly use the OCI or DBMS_LOB COPY command, and copy the temporary LOB into a permanent one.

Security is provided through the LOB locator. Only the user who created the temporary LOB is able to see it. Locators are not expected to be able to pass from one user's session to another. Even if someone did pass a locator from one session to another, they would not access the temporary LOBs from the original session. Temporary LOB lookup is localized to each user's own session. Someone using a locator from somewhere else is only able to access LOBs within his own session that have the same LOB ID. Users should not try to do this, but if they do, they are not able to affect anyone else's data.

The database keeps track of temporary LOBs for each session in a v$ view called V$TEMPORARY_LOBS, which contains information about how many temporary LOBs exist for each session. V$ views are for DBA use. From the session, the database can determine which user owns the temporary LOBs. By using V$TEMPORARY_LOBS in conjunction with DBA_SEGMENTS, a DBA can see how much space is being used by a session for temporary LOBs. These tables can be used by DBAs to monitor and guide any emergency cleanup of temporary space used by temporary LOBs.

The following notes are specific to temporary LOBs:

  1. All functions in DBMS_LOB return NULL if any of the input parameters are NULL. All procedures in DBMS_LOB raise an exception if the LOB locator is input as NULL.
  2. Operations based on CLOBs do not verify if the character set IDs of the parameters (CLOB parameters, VARCHAR2 buffers and patterns, and so on) match. It is the user's responsibility to ensure this.
  3. Data storage resources are controlled by the DBA by creating different temporary tablespaces. DBAs can define separate temporary tablespaces for different users, if necessary.
  4. Temporary LOBs still adhere to value semantics in order to be consistent with permanent LOBs and to try to conform to the ANSI standard for LOBs. As a result, each time a user does an OCILobLocatatorAssign, or the equivalent assignment in PL/SQL, the database makes a copy of the temporary LOB.

    Each locator points to its own LOB value. If one locator is used to create a temporary LOB, and then is assigned to another LOB locator using OCILobLOcatorAssign in OCI or through an assignment operation in PL/SQL, then the database copies the original temporary LOB and causes the second locator to point to the copy.

    In order for users to modify the same LOB, they must go through the same locator. In OCI, this can be accomplished fairly easily by using pointers to locators and assigning the pointers to point to the same locator. In PL/SQL, the same LOB variable must be used to update the LOB to get this effect.

    The following example shows a place where a user incurs a copy, or at least an extra round-trip to the server.

    DECLARE 
      a blob; 
      b blob; 
    BEGIN 
      dbms_lob.createtemporary(b, TRUE); 
      -- the following assignment results in a deep copy 
      a := b; 
    END; 
     
    

    The PL/SQL compiler makes temporary copies of actual arguments bound to OUT or IN OUT parameters. If the actual parameter is a temporary LOB, then the temporary copy is a deep (value) copy.

    The following PL/SQL block illustrates the case where the user incurs a deep copy by passing a temporary LOB as an IN OUT parameter.

    DECLARE 
      a blob; 
      procedure foo(parm IN OUT blob) is 
      BEGIN 
       ... 
      END; 
    BEGIN 
      dbms_lob.createtemporary(a, TRUE); 
      -- the following call results in a deep copy of the blob a 
      foo(a); 
    END; 
     
    

    To minimize deep copies on PL/SQL parameter passing, use the NOCOPY compiler hint where possible.

    The duration parameter passed to dbms_lob.createtemporary() is a hint. The duration of the new temp LOB is the same as the duration of the locator variable in PL/SQL. For example, in the preceding program block, the program variable a has the duration of the residing frame. Therefore at the end of the block, memory of a will be freed at the end of the function.

    If a PL/SQL package variable is used to create a temp LOB, it will have the duration of the package variable, which has a duration of SESSION.

    BEGIN 
       y clob; 
      END; 
    /
    BEGIN 
       dbms_lob.createtemporary(package.y, TRUE); 
    END; 
    
    See Also:

    PL/SQL User's Guide and Reference for more information on NOCOPY syntax


Exceptions

Table 45-2 DBMS_LOB Exceptions
Exception Code Description

INVALID_ARGVAL

21560

The argument is expecting a nonNULL, valid value but the argument value passed in is NULL, invalid, or out of range.

ACCESS_ERROR

22925

You are trying to write too much data to the LOB: LOB size is limited to 4 gigabytes.

NOEXIST_DIRECTORY

22285

The directory leading to the file does not exist.

NOPRIV_DIRECTORY

22286

The user does not have the necessary access privileges on the directory or the file for the operation.

INVALID_DIRECTORY

22287

The directory used for the current operation is not valid if being accessed for the first time, or if it has been modified by the DBA since the last access.

OPERATION_FAILED

22288

The operation attempted on the file failed.

UNOPENED_FILE

22289

The file is not open for the required operation to be performed.

OPEN_TOOMANY

22290

The number of open files has reached the maximum limit.

NO_DATA_FOUND

 

EndofLob indicator for looping read operations. This is not a hard error.

VALUE_ERROR

6502

PL/SQL error for invalid values to subprogram's parameters.


Summary of DBMS_LOB Subprograms

Table 45-3  DBMS_LOB Package Subprograms
Subprogram Description

APPEND Procedure

Appends the contents of the source LOB to the destination LOB

CLOSE Procedure

Closes a previously opened internal or external LOB

COMPARE Function

Compares two entire LOBs or parts of two LOBs

CONVERTTOBLOB Procedure

Reads character data from a source CLOB or NCLOB instance, converts the character data to the specified character, writes the converted data to a destination BLOB instance in binary format, and returns the new offsets

CONVERTTOCLOB Procedure

Takes a source BLOB instance, converts the binary data in the source instance to character data using the specified character, writes the character data to a destination CLOB or NCLOB instance, and returns the new offsets

COPY Procedure

Copies all, or part, of the source LOB to the destination LOB

CREATETEMPORARY Procedure

Creates a temporary BLOB or CLOB and its corresponding index in the user's default temporary tablespace

ERASE Procedure

Erases all or part of a LOB

FILECLOSE Procedure

Closes the file

FILECLOSEALL Procedure

Closes all previously opened files

FILEEXISTS Function

Checks if the file exists on the server

FILEGETNAME Procedure

Gets the directory object name and file name

FILEISOPEN Function

Checks if the file was opened using the input BFILE locators

FILEOPEN Procedure

Opens a file

FREETEMPORARY Procedure

Frees the temporary BLOB or CLOB in the user's default temporary tablespace

GETCHUNKSIZE Function

Returns the amount of space used in the LOB chunk to store the LOB value

GETLENGTH Function

Gets the length of the LOB value

GET_STORAGE_LIMIT

Returns the storage limit for LOBs in your database configuration

INSTR Function

Returns the matching position of the nth occurrence of the pattern in the LOB

ISOPEN Function

Checks to see if the LOB was already opened using the input locator

ISTEMPORARY Function

Checks if the locator is pointing to a temporary LOB

LOADFROMFILE Procedure

Loads BFILE data into an internal LOB

LOADBLOBFROMFILE Procedure

Loads BFILE data into an internal BLOB

LOADCLOBFROMFILE Procedure

Loads BFILE data into an internal CLOB

OPEN Procedure

Opens a LOB (internal, external, or temporary) in the indicated mode

READ Procedure

Reads data from the LOB starting at the specified offset

SUBSTR Function

Returns part of the LOB value starting at the specified offset

TRIM Procedure

Trims the LOB value to the specified shorter length

WRITE Procedure

Writes data to the LOB from a specified offset

WRITEAPPEND Procedure

Writes a buffer to the end of a LOB


APPEND Procedure

This procedure appends the contents of a source internal LOB to a destination LOB. It appends the complete source LOB.

There are two overloaded APPEND procedures.

Syntax

DBMS_LOB.APPEND (
   dest_lob IN OUT  NOCOPY BLOB, 
   src_lob  IN             BLOB); 

DBMS_LOB.APPEND (
   dest_lob IN OUT  NOCOPY CLOB  CHARACTER SET ANY_CS, 
   src_lob  IN             CLOB  CHARACTER SET dest_lob%CHARSET);

Parameters

Table 45-4 APPEND Procedure Parameters
Parameter Description

dest_lob

Locator for the internal LOB to which the data is to be appended.

src_lob

Locator for the internal LOB from which the data is to be read.

Exceptions

Table 45-5 APPEND Procedure Exceptions
Exception Description

VALUE_ERROR

Either the source or the destination LOB is NULL.

Usage Notes

It is not mandatory that you wrap the LOB operation inside the Open/Close APIs. If you did not open the LOB before performing the operation, the functional and domain indexes on the LOB column are updated during the call. However, if you opened the LOB before performing the operation, you must close it before you commit or rollback the transaction. When an internal LOB is closed, it updates the functional and domain indexes on the LOB column.

If you do not wrap the LOB operation inside the Open/Close API, the functional and domain indexes are updated each time you write to the LOB. This can adversely affect performance. Therefore, it is recommended that you enclose write operations to the LOB within the OPEN or CLOSE statement.

See Also:

Oracle Database Application Developer's Guide - Large Objects for additional details on usage of this procedure


CLOSE Procedure

This procedure closes a previously opened internal or external LOB.

Syntax

DBMS_LOB.CLOSE (
   lob_loc    IN OUT NOCOPY BLOB); 

DBMS_LOB.CLOSE (
   lob_loc    IN OUT NOCOPY CLOB CHARACTER SET ANY_CS); 

DBMS_LOB.CLOSE (
   file_loc   IN OUT NOCOPY BFILE); 

Parameters

Table 45-6 CLOSE Procedure Parameters
Parameter Description

lob_loc

LOB locator. For more information, see Operational Notes.

Exceptions

No error is returned if the BFILE exists but is not opened. An error is returned if the LOB is not open.

Usage Notes

CLOSE requires a round-trip to the server for both internal and external LOBs. For internal LOBs, CLOSE triggers other code that relies on the close call, and for external LOBs (BFILEs), CLOSE actually closes the server-side operating system file.

It is not mandatory that you wrap all LOB operations inside the Open/Close APIs. However, if you open a LOB, you must close it before you commit or rollback the transaction; an error is produced if you do not. When an internal LOB is closed, it updates the functional and domain indexes on the LOB column.

It is an error to commit the transaction before closing all opened LOBs that were opened by the transaction. When the error is returned, the openness of the open LOBs is discarded, but the transaction is successfully committed. Hence, all the changes made to the LOB and non-LOB data in the transaction are committed, but the domain and function-based indexes are not updated. If this happens, you should rebuild the functional and domain indexes on the LOB column.

See Also:

Oracle Database Application Developer's Guide - Large Objects for additional details on usage of this procedure


COMPARE Function

This function compares two entire LOBs or parts of two LOBs.

Syntax

DBMS_LOB.COMPARE (
   lob_1            IN BLOB,
   lob_2            IN BLOB,
   amount           IN INTEGER := 4294967295,
   offset_1         IN INTEGER := 1,
   offset_2         IN INTEGER := 1)
  RETURN INTEGER;

DBMS_LOB.COMPARE (
   lob_1            IN CLOB  CHARACTER SET ANY_CS,
   lob_2            IN CLOB  CHARACTER SET lob_1%CHARSET,
   amount           IN INTEGER := 4294967295,
   offset_1         IN INTEGER := 1,
   offset_2         IN INTEGER := 1)
  RETURN INTEGER; 

DBMS_LOB.COMPARE (
   lob_1            IN BFILE,
   lob_2            IN BFILE,
   amount           IN INTEGER,
   offset_1         IN INTEGER := 1,
   offset_2         IN INTEGER := 1)
  RETURN INTEGER;

Pragmas

pragma restrict_references(COMPARE, WNDS, WNPS, RNDS, RNPS);

Parameters

Table 45-7 COMPARE Function Parameters
Parameter Description

lob_1

LOB locator of first target for comparison.

lob_2

LOB locator of second target for comparison.

amount

Number of bytes (for BLOBs) or characters (for CLOBs) to compare.

offset_1

Offset in bytes or characters on the first LOB (origin: 1) for the comparison.

offset_2

Offset in bytes or characters on the first LOB (origin: 1) for the comparison.

Return Values

Usage Notes

You can only compare LOBs of the same datatype (LOBs of BLOB type with other BLOBs, and CLOBs with CLOBs, and BFILEs with BFILEs). For BFILEs, the file must be already opened using a successful FILEOPEN operation for this operation to succeed.

COMPARE returns zero if the data exactly matches over the range specified by the offset and amount parameters. Otherwise, a nonzero INTEGER is returned.

For fixed-width n-byte CLOBs, if the input amount for COMPARE is specified to be greater than (4294967295/n), then COMPARE matches characters in a range of size (4294967295/n), or Max(length(clob1), length(clob2)), whichever is lesser.

Exceptions

Table 45-8 COMPARE Function Exceptions for BFILE operations
Exception Description

UNOPENED_FILE

File was not opened using the input locator.

NOEXIST_DIRECTORY

Directory does not exist.

NOPRIV_DIRECTORY

You do not have privileges for the directory.

INVALID_DIRECTORY

Directory has been invalidated after the file was opened.

INVALID_OPERATION

File does not exist, or you do not have access privileges on the file.

See Also:

Oracle Database Application Developer's Guide - Large Objects for additional details on usage of this procedure


CONVERTTOBLOB Procedure

This procedure reads character data from a source CLOB or NCLOB instance, converts the character data to the character set you specify, writes the converted data to a destination BLOB instance in binary format, and returns the new offsets. You can use this interface with any combination of persistent or temporary LOB instances as the source or destination.

Syntax

DBMS_LOB.CONVERTTOBLOB(
  dest_lob       IN OUT     NOCOPY  BLOB,
  src_clob       IN         CLOB CHARACTER SET ANY_CS,
  amount         IN         INTEGER,
  dest_offset    IN OUT     INTEGER,
  src_offset     IN OUT     INTEGER, 
  blob_csid      IN         NUMBER,
  lang_context   IN OUT     INTEGER,
  warning        OUT        INTEGER); 

Parameters

Table 45-9  CONVERTTOBLOB Procedure Parameters  
Parameter Description

dest_lob

LOB locator of the destination LOB instance.

src_blob

LOB locator of the source LOB instance.

amount

Number of characters to convert from the source LOB.

If you want to copy the entire LOB, pass the constant DBMS_LOB.LOBMAXSIZE. If you pass any other value, it must be less than or equal to the size of the LOB.

dest_offset

(IN)Offset in bytes in the destination LOB for the start of the write. Specify a value of 1 to start at the beginning of the LOB.

(OUT)The new offset in bytes after the end of the write.

src_offset

(IN)Offset in characters in the source LOB for the start of the read.

(OUT)Offset in characters in the source LOB right after the end of the read.

blob_csid

Desired character set ID of the converted data.

lang_context

(IN) Language context, such as shift status, for the current conversion.

(OUT) The language context at the time when the current conversion is done.

This information is returned so you can use it for subsequent conversions without losing or misinterpreting any source data. For the very first conversion, or if do not care, use the default value of zero.

warning

(OUT) Warning message. This parameter indicates when something abnormal happened during the conversion. You are responsible for checking the warning message.

Currently, the only possible warning is -- inconvertible character. This occurs when the character in the source cannot be properly converted to a character in destination. The default replacement character (for example, '?') is used in place of the inconvertible character. The return value of this error message is defined as the constant warn_inconvertable_char in the DBMS_LOB package.

Usage Notes

Preconditions

Before calling the CONVERTTOBLOB procedure, the following preconditions must be met:

Constants and Defaults

All parameters are required. You must pass a variable for each OUT or IN OUT parameter. You must pass either a variable or a value for each IN parameter.

Table 45-10 gives a summary of typical values for each parameter. The first column lists the parameter, the second column lists the typical value, and the last column describes the result of passing the value. Note that constants are used for some values. These constants are defined in the dbmslob.sql package specification file.

Table 45-10  DBMS_LOB.CONVERTTOBLOB Typical Values

Parameter

Value

Description

amount

lobmaxsize (IN)

convert the entire file

dest_offset

1 (IN)

start from the beginning

src_offset

1 (IN)

start from the beginning

csid

default_csid (IN)

default csid, use same csid as source LOB

lang_context

default_lang_ctx (IN)

default language context

warning

no_warning (OUT)

warn_inconvertible_char (OUT)

no warning message, success

character in source cannot be properly converted

General Notes

You must specify the desired character set for the destination LOB in the blob_csid parameter. You can pass a zero value for blob_csid. When you do so, the database assumes that the desired character set is the same as the source LOB character set, and performs a binary copy of the data--no character set conversion is performed.

You must specify the offsets for both the source and destination LOBs, and the number of bytes to copy from the source LOB. The amount and src_offset values are in characters and the dest_offset is in bytes. To convert the entire LOB, you can specify LOBMAXSIZE for the amount parameter.

Exceptions

Table 45-11 gives possible exceptions this procedure can throw. The first column lists the exception string and the second column describes the error conditions that can cause the exception.

Table 45-11  CONVERTTOBLOB Procedure Exceptions
Exception Description
VALUE_ERROR

Any of the input parameters are NULL or INVALID.

INVALID_ARGVAL

One or more of the following:

- src_offset or dest_offset < 1.

- src_offset or dest_offset > LOBMAXSIZE.

- amount < 1.

- amount > LOBMAXSIZE.

See Also:

Oracle Database Application Developer's Guide - Large Objects for more information on using LOBs in application development


CONVERTTOCLOB Procedure

This procedure takes a source BLOB instance, converts the binary data in the source instance to character data using the character set you specify, writes the character data to a destination CLOB or NCLOB instance, and returns the new offsets. You can use this interface with any combination of persistent or temporary LOB instances as the source or destination.

Syntax

DBMS_LOB.CONVERTTOCLOB(
   dest_lob       IN OUT NOCOPY  CLOB CHARACTER SET ANY_CS,
   src_blob       IN             BLOB,
   amount         IN             INTEGER,
   dest_offset    IN OUT         INTEGER,
   src_offset     IN OUT         INTEGER, 
   blob_csid      IN             NUMBER,
   lang_context   IN OUT         INTEGER,
   warning        OUT            INTEGER);

Parameters

Table 45-12  CONVERTTOCLOB Procedure Parameters  
Parameter Description

dest_lob

LOB locator of the destination LOB instance.

src_blob

LOB locator of the source LOB instance.

amount

Number of bytes to convert from the source LOB.

If you want to copy the entire BLOB, pass the constant DBMS_LOB.LOBMAXSIZE. If you pass any other value, it must be less than or equal to the size of the BLOB.

dest_offset

(IN) Offset in characters in the destination LOB for the start of the write. Specify a value of 1 to start at the beginning of the LOB.

(OUT) The new offset in characters after the end of the write. This offset always points to the beginning of the first complete character after the end of the write.

src_offset

(IN) Offset in bytes in the source LOB for the start of the read.

(OUT) Offset in bytes in the source LOB right after the end of the read.

blob_csid

Desired character set ID of the converted data.

lang_context

(IN) Language context, such as shift status, for the current conversion.

(OUT) The language context at the time when the current conversion is done.

This information is returned so you can use it for subsequent conversions without losing or misinterpreting any source data. For the very first conversion, or if do not care, use the default value of zero.

warning

Warning message. This parameter indicates when something abnormal happened during the conversion. You are responsible for checking the warning message.

Currently, the only possible warning is -- inconvertible character. This occurs when the character in the source cannot be properly converted to a character in destination. The default replacement character (for example, '?') is used in place of the inconvertible character. The return value of this error message is defined as the constant warn_inconvertable_char in the DBMS_LOB package.

Usage Notes

Preconditions

Before calling the CONVERTTOCLOB procedure, the following preconditions must be met:

Constants and Defaults

All parameters are required. You must pass a variable for each OUT or IN OUT parameter. You must pass either a variable or a value for each IN parameter.

Table 45-13 gives a summary of typical values for each parameter. The first column lists the parameter, the second column lists the typical value, and the last column describes the result of passing the value. Note that constants are used for some values. These constants are defined in the dbmslob.sql package specification file.

Table 45-13  DBMS_LOB.CONVERTTOCLOB Typical Values

Parameter

Value

Description

amount

lobmaxsize (IN)

convert the entire file

dest_offset

1 (IN)

start from the beginning

src_offset

1 (IN)

start from the beginning

csid

default_csid (IN)

default csid, use destination csid

lang_context

default_lang_ctx (IN)

default language context

warning

no_warning (OUT)

warn_inconvertible_char (OUT)

no warning message, success

character in source cannot be properly converted

General Notes

You must specify the desired character set for the destination LOB in the blob_csid parameter. You can pass a zero value for blob_csid. When you do so, the database assumes that the BLOB contains character data in the same character set as the destination CLOB, and performs a binary copy of the data to the destination LOB, no character set conversion being performed.

You must specify the offsets for both the source and destination LOBs, and the number of bytes to copy from the source BLOB. The amount and src_offset values are in bytes and the dest_offset is in characters. To convert the entire BLOB, you can specify LOBMAXSIZE for the amount parameter.

Exceptions

Table 45-14  CONVERTTOCLOB Procedure Exceptions
Exception Description

VALUE_ERROR

Any of the input parameters are NULL or INVALID.

INVALID_ARGVAL

One or more of the following:

- src_offset or dest_offset < 1.

- src_offset or dest_offset > LOBMAXSIZE.

- amount < 1.

- amount > LOBMAXSIZE.

See Also:

Oracle Database Application Developer's Guide - Large Objects for more information on using LOBs in application development


COPY Procedure

This procedure copies all, or a part of, a source internal LOB to a destination internal LOB. You can specify the offsets for both the source and destination LOBs, and the number of bytes or characters to copy.

Syntax

DBMS_LOB.COPY (
  dest_lob    IN OUT NOCOPY BLOB,
  src_lob     IN            BLOB,
  amount      IN            INTEGER,
  dest_offset IN            INTEGER := 1,
  src_offset  IN            INTEGER := 1);

DBMS_LOB.COPY ( 
  dest_lob    IN OUT NOCOPY CLOB  CHARACTER SET ANY_CS,
  src_lob     IN            CLOB  CHARACTER SET dest_lob%CHARSET,
  amount      IN            INTEGER,
  dest_offset IN            INTEGER := 1,
  src_offset  IN            INTEGER := 1);

Parameters

Table 45-15 COPY Procedure Parameters
Parameter Description

dest_lob

LOB locator of the copy target.

src_lob

LOB locator of source for the copy.

amount

Number of bytes (for BLOBs) or characters (for CLOBs) to copy.

dest_offset

Offset in bytes or characters in the destination LOB (origin: 1) for the start of the copy.

src_offset

Offset in bytes or characters in the source LOB (origin: 1) for the start of the copy.

Exceptions

Table 45-16  COPY Procedure Exceptions
Exception Description

VALUE_ERROR

Any of the input parameters are NULL or invalid.

INVALID_ARGVAL

Either:

- src_offset or dest_offset < 1

- src_offset or dest_offset > LOBMAXSIZE

- amount < 1

- amount > LOBMAXSIZE

Usage Notes

If the offset you specify in the destination LOB is beyond the end of the data currently in this LOB, then zero-byte fillers or spaces are inserted in the destination BLOB or CLOB respectively. If the offset is less than the current length of the destination LOB, then existing data is overwritten.

It is not an error to specify an amount that exceeds the length of the data in the source LOB. Thus, you can specify a large amount to copy from the source LOB, which copies data from the src_offset to the end of the source LOB.

It is not mandatory that you wrap the LOB operation inside the Open/Close APIs. If you did not open the LOB before performing the operation, the functional and domain indexes on the LOB column are updated during the call. However, if you opened the LOB before performing the operation, you must close it before you commit or rollback the transaction. When an internal LOB is closed, it updates the functional and domain indexes on the LOB column.

If you do not wrap the LOB operation inside the Open/Close API, the functional and domain indexes are updated each time you write to the LOB. This can adversely affect performance. Therefore, it is recommended that you enclose write operations to the LOB within the OPEN or CLOSE statement.

See Also:

Oracle Database Application Developer's Guide - Large Objects for additional details on usage of this procedure


CREATETEMPORARY Procedure

This procedure creates a temporary BLOB or CLOB and its corresponding index in your default temporary tablespace.

Syntax

DBMS_LOB.CREATETEMPORARY (
   lob_loc IN OUT NOCOPY BLOB,
   cache   IN            BOOLEAN,
   dur     IN            PLS_INTEGER := 10);
  
DBMS_LOB.CREATETEMPORARY (
   lob_loc IN OUT NOCOPY CLOB CHARACTER SET ANY_CS,
   cache   IN            BOOLEAN,
   dur     IN            PLS_INTEGER := 10);

Parameters

Table 45-17 CREATETEMPORARY Procedure Parameters
Parameter Description
lob_loc

LOB locator. For more information, see Operational Notes.

cache

Specifies if LOB should be read into buffer cache or not.

dur

1 of 2 predefined duration values (SESSION or CALL) which specifies a hint as to whether the temporary LOB is cleaned up at the end of the session or call.

If dur is omitted, then the session duration is used.

See Also:

ERASE Procedure

This procedure erases an entire internal LOB or part of an internal LOB.

Syntax

DBMS_LOB.ERASE (
   lob_loc           IN OUT   NOCOPY   BLOB,
   amount            IN OUT   NOCOPY   INTEGER,
   offset            IN                INTEGER := 1);

DBMS_LOB.ERASE (
   lob_loc           IN OUT   NOCOPY   CLOB CHARACTER SET ANY_CS,
   amount            IN OUT   NOCOPY   INTEGER,
   offset            IN                INTEGER := 1);

Parameters

Table 45-18 ERASE Procedure Parameters
Parameter Description

lob_loc

Locator for the LOB to be erased.For more information, see Operational Notes.

amount

Number of bytes (for BLOBs or BFILES) or characters (for CLOBs or NCLOBs) to be erased.

offset

Absolute offset (origin: 1) from the beginning of the LOB in bytes (for BLOBs) or characters (CLOBs).

Usage Notes


Note:

The length of the LOB is not decreased when a section of the LOB is erased. To decrease the length of the LOB value, see the "TRIM Procedure".


When data is erased from the middle of a LOB, zero-byte fillers or spaces are written for BLOBs or CLOBs respectively.

The actual number of bytes or characters erased can differ from the number you specified in the amount parameter if the end of the LOB value is reached before erasing the specified number. The actual number of characters or bytes erased is returned in the amount parameter.

Exceptions

Table 45-19 ERASE Procedure Exceptions
Exception Description

VALUE_ERROR

Any input parameter is NULL.

INVALID_ARGVAL

Either:

- amount < 1 or amount > LOBMAXSIZE

- offset < 1 or offset > LOBMAXSIZE

Usage Notes

It is not mandatory that you wrap the LOB operation inside the Open/Close APIs. If you did not open the LOB before performing the operation, the functional and domain indexes on the LOB column are updated during the call. However, if you opened the LOB before performing the operation, you must close it before you commit or rollback the transaction. When an internal LOB is closed, it updates the functional and domain indexes on the LOB column.

If you do not wrap the LOB operation inside the Open/Close API, the functional and domain indexes are updated each time you write to the LOB. This can adversely affect performance. Therefore, it is recommended that you enclose write operations to the LOB within the OPEN or CLOSE statement.

See Also:

FILECLOSE Procedure

This procedure closes a BFILE that has already been opened through the input locator.


Note:

The database has only read-only access to BFILEs. This means that BFILEs cannot be written through the database.


Syntax

DBMS_LOB.FILECLOSE (
    file_loc IN OUT NOCOPY BFILE); 

Parameters

Table 45-20 FILECLOSE Procedure Parameter
Parameter Description

file_loc

Locator for the BFILE to be closed.

Exceptions

Table 45-21 FILECLOSE Procedure Exceptions
Exception Description

VALUE_ERROR

NULL input value for file_loc.

UNOPENED_FILE

File was not opened with the input locator.

NOEXIST_DIRECTORY

Directory does not exist.

NOPRIV_DIRECTORY

You do not have privileges for the directory.

INVALID_DIRECTORY

Directory has been invalidated after the file was opened.

INVALID_OPERATION

File does not exist, or you do not have access privileges on the file.

See Also:

FILECLOSEALL Procedure

This procedure closes all BFILEs opened in the session.

Syntax

DBMS_LOB.FILECLOSEALL;