Skip Headers

Oracle9i Application Developer's Guide - Large Objects (LOBs)
Release 2 (9.2)

Part Number A96591-01
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback

Go to previous page Go to next page

3
LOB Support in Different Programmatic Environments

This chapter discusses the following topics:

Eight Programmatic Environments Operate on LOBs

Table 3-1 lists the eight programmatic environments (languages) that support LOB functionality. Chapter 10, Chapter 11, and Chapter 12 cover the supported LOB functions in terms of use cases. Examples are provided in each programmatic environment for most LOB use cases.

Table 3-1 LOBs' Eight Programmatic Environments
Language Precompiler or Interface Program Syntax Reference In This Chapter See...

PL/SQL

DBMS_LOB Package

Oracle9i Supplied PL/SQL Packages and Types Reference

"Using PL/SQL (DBMS_LOB Package) To Work With LOBs".

C

Oracle Call Interface for C (OCI)

Oracle Call Interface Programmer's Guide

"Using C (OCI) To Work With LOBs".

C++

Oracle Call Interface for C++ (OCCI)

Oracle C++ Call Interface Programmer's Guide

"Using C++ (OCCI) To Work With LOBs"

C/C++

Pro*C/C++ Precompiler

Pro*C/C++ Precompiler Programmer's Guide

"Using C/C++ (Pro*C) To Work with LOBs".

COBOL

Pro*COBOL Precompiler

Pro*COBOL Precompiler Programmer's Guide

"Using COBOL (Pro*COBOL) to Work with LOBs".

Visual Basic

Oracle Objects For OLE (OO4O)

Oracle Objects for OLE (OO4O) is a Windows-based product included with Oracle9i Client for Windows NT.

There are no manuals for this product, only online help. Online help is available through the Application Development submenu of the Oracle9i installation.

"Using Visual Basic (Oracle Objects for OLE (OO4O)) to Work with LOBs"."

Java

JDBC Application Programmatic Interface (API)

Oracle9i SQLJ Developer's Guide and Reference and Oracle9i JDBC Developer's Guide and Reference.

"Using Java (JDBC) To Work with LOBs".

OLEDB

OraOLEDB, an OLE DB provider for Oracle.

Oracle Provider for OLE DB Developer's Guide

Comparing the LOB Interfaces

Table 3-2 and Table 3-3compare the eight LOB programmatic interfaces by listing their functions and methods used to operate on LOBs. The tables are split in two simply to accommodate all eight interfaces. The interfaces' functionality, with regards LOBs, is described in the following sections.

Table 3-2 Comparing the LOB Interfaces, 1 of 2  
PL/SQL: DBMS_LOB (dbmslob.sql) C (OCI) (ociap.h) C++ (OCCI) (occiData.h). Also for OCCIClob and OCCIBfile classes. Pro*C/C++ and Pro*COBOL

DBMS_LOB.COMPARE

N/A

N/A

N/A

DBMS_LOB.INSTR

N/A

N/A

N/A

DBMS_LOB.SUBSTR

N/A

N/A

N/A

DBMS_LOB.APPEND

OCILob.Append

OCCIBlob.append()

APPEND

N/A [use PL/SQL assign operator]

OCILob.Assign

ASSIGN

N/A

OCILob.CharSetForm

OCCIClob.getCharsetForm (CLOB only)

N/A

N/A

OCILob.CharSetId

OCCIClob.getCharsetId()

(CLOB only)

N/A

DBMS_LOB.CLOSE

OCILob.Close

OCCIBlob.close()

CLOSE

N/A

N/A

OCCIClob.closeStream()

N/A

DBMS_LOB.COPY

OCILob.Copy

OCCIBlob.copy()

COPY

N/A

OCILob.DisableBuffering

N/A

DISABLE BUFFERING

N/A

OCILob.EnableBuffering

N/A

ENABLE BUFFERING

DBMS_LOB.ERASE

OCILob.Erase

N/A

ERASE

DBMS_LOB.FILECLOSE

OCILob.FileClose

OCCIClob.close()

CLOSE

DBMS_LOB.FILECLOSEALL

OCILob.FileCloseAll

N/A

FILE CLOSE ALL

DBMS_LOB.FILEEXISTS

OCILob.FileExists

OCCIBfile.fileExists()

DESCRIBE [FILEEXISTS]

DBMS_LOB.GETCHUNKSIZE

OCILob.GetChunkSize

OCCIBlob.getChunkSize()

DESCRIBE [CHUNKSIZE]

DBMS_LOB.FILEGETNAME

OCILob.FileGetName

OCCIBfile.getFileName() and OCCIBfile.getDirAlias()

DESCRIBE [DIRECTORY, FILENAME]

DBMS_LOB.FILEISOPEN

OCILob.FileIsOpen

OCCIBfile.isOpen()

DESCRIBE [ISOPEN]

DBMS_LOB.FILEOPEN

OCILob.FileOpen

OCCIBfile.open()

OPEN

N/A (use BFILENAME operator)

OCILob.FileSetName

OCCIBfile.setName()

FILE SET

N/A

OCILob.FlushBuffer

N/A

FLUSH BUFFER

DBMS_LOB.GETLENGTH

OCILob.GetLength

OCCIBlob.length()

DESCRIBE [LENGTH]

N/A

OCILob.IsEqual

use operator = ( )=/!=

N/A

DBMS_LOB.ISOPEN

OCILob.IsOpen

OCCIBlob.isOpen()

DESCRIBE [ISOPEN]

DBMS_LOB.LOADFROMFILE

OCILob.LoadFromFile

Use the overloadedcopy() method.

LOAD FROM FILE

N/A

OCILob.LocatorIsInit

OCCIClob.isinitialized()

N/A

DBMS_LOB.OPEN

OCILob.Open

OCCIBlob.open

OPEN

DBMS_LOB.READ

OCILob.Read

OCCIBlob.read

READ

DBMS_LOB.TRIM

OCILob.Trim

OCCIBlob.trim

TRIM

DBMS_LOB.WRITE

OCILob.Write

OCCIBlob.write

WRITEORALOB.

DBMS_LOB.WRITEAPPEND

OCILob.WriteAppend

N/A

WRITE APPEND

DBMS_LOB.CREATETEMPORARY

OCILob.CreateTemporary

N/A

N/A

DBMS_LOB.FREETEMPORARY

OCILob.FreeTemporary

N/A

N/A

DBMS_LOB.ISTEMPORARY

OCILob.IsTemporary

N/A

N/A

OCILob.LocatorAssign

use operator = ( ) or copy constructor

N/A

Table 3-3 Comparing the LOB Interfaces, 2 of 2  
PL/SQL: DBMS_LOB (dbmslob.sql) Visual Basic (OO4O) Java (JDBC OLEDB

DBMS_LOB.COMPARE

ORALOB.Compare

Use DBMS_LOB.

N/A

DBMS_LOB.INSTR

ORALOB.Matchpos

position

N/A

DBMS_LOB.SUBSTR

N/A

getBytes for BLOBs or BFILEs

getSubString for CLOBs

N/A

DBMS_LOB.APPEND

ORALOB.Append

Use length and then putBytes or PutString

N/A

N/A [use PL/SQL assign operator]

ORALOB.Clone

N/A [use equal sign]

N/A

N/A

N/A

N/A

N/A

N/A

N/A

N/A

N/A

DBMS_LOB.CLOSE

N/A

use DBMS_LOB.

N/A

DBMS_LOB.COPY

ORALOB.Copy

Use read and write

N/A

N/A

ORALOB.DisableBuffering

N/A

N/A

N/A

ORALOB.EnableBuffering

N/A

N/A

DBMS_LOB.ERASE

ORALOB.Erase

Use DBMS_LOB.

N/A

DBMS_LOB.FILECLOSE

ORABFILE.Close

closeFile

N/A

DBMS_LOB.FILECLOSEALL

ORABFILE.CloseAll

Use DBMS_LOB.

N/A

DBMS_LOB.FILEEXISTS

ORABFILE.Exist

fileExists

N/A

DBMS_LOB.GETCHUNKSIZE

N/A

getChunkSize

N/A

DBMS_LOB.FILEGETNAME

ORABFILE.

DirectoryName

ORABFILE.

FileName

getDirAlias

getName

N/A

DBMS_LOB.FILEISOPEN

ORABFILE.IsOpen

Use DBMS_LOB.ISOPEN

N/A

DBMS_LOB.FILEOPEN

ORABFILE.Open

openFile

N/A

N/A (use BFILENAME operator)

DirectoryName

FileName

Use BFILENAME

N/A

N/A

ORALOB.FlushBuffer

N/A

N/A

DBMS_LOB.GETLENGTH

ORALOB.Size

length

N/A

N/A

N/A

equals

N/A

DBMS_LOB.ISOPEN

ORALOB.IsOpen

use DBMS_LOB. IsOpen

N/A

DBMS_LOB.LOADFROMFILE

ORALOB.

CopyFromBfile

Use read and then write

N/A

DBMS_LOB.OPEN

ORALOB.open

Use DBMS_LOB.

N/A

DBMS_LOB.READ

ORALOB.Read

BLOB or BFILE: getBytes and getBinaryStream

CLOB: getString and getSubString and getCharacterStream

IRowset::GetData and ISequentialStream::Read

DBMS_LOB.TRIM

ORALOB.Trim

Use DBMS_LOB.

N/A

DBMS_LOB.WRITE

ORALOB.Write

BLOB or BFILE: putBytes and getBinaryOutputStream

CLOB: putString and getCharacterOutputStream

IRowsetChange::SetData

and

ISequentialStream::Write

DBMS_LOB.WRITEAPPEND

N/A

Use length and then putString or putBytes

N/A

DBMS_LOB.CREATETEMPORARY

N/A

N/A

N/A

DBMS_LOB.FREETEMPORARY

N/A

N/A

N/A

DBMS_LOB.ISTEMPORARY

N/A

N/A

N/A

Using PL/SQL (DBMS_LOB Package) To Work With LOBs

The PL/SQL DBMS_LOB package can be used for the following operations:

Provide a LOB Locator Before Invoking the DBMS_LOB Routine

As described in more detail in the following, DBMS_LOB routines work based on LOB locators. For the successful completion of DBMS_LOB routines, you must provide an input locator representing a LOB that exists in the database tablespaces or external file system, before you invoke the routine.

Once the LOBs are defined and created, you may then SELECT 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.

Examples provided with each DBMS_LOB routine will illustrate this in the following sections.

PL/SQL - LOB Guidelines

Client PL/SQL Procedures Cannot Call DBMS_LOB Routines

Client-side PL/SQL procedures cannot call DBMS_LOB package routines.

However, you can use server-side PL/SQL procedures or anonymous blocks in Pro*C/C++ to call DBMS_LOB package routines.

Offset and Amount Parameters: Fixed-Width Versus Varying-Width, Character or Byte For DBMS_LOB Package

For DBMS_LOB package, for example, for both fixed and varying-width character sets, the following rules apply:

DBMS_LOB.LOADFROMFILE: Amount Parameter Value

When using DBMS_LOB.LOADFROMFILE, you cannot specify an amount parameter value larger than the size of the BFILE. (Although you can specify the LOBMAXSIZE constant for the amount parameter value to load the entire BFILE.)

DBMS_LOB.READ: Amount Parameter Can be Larger than Data Size

When using DBMS_LOB.READ, the amount parameter can be larger than the size of the data. In PL/SQL, the amount should be less than or equal to the size of the buffer, and the buffer size is limited to 32K.

See Also:

PL/SQL Functions and Procedures that Operate on LOBs

PL/SQL functions and procedures that operate on BLOBs, CLOBs, NCLOBs, and BFILEs are summarized in the following:

PL/SQL Functions/Procedures To Modify BLOB, CLOB, and NCLOB Values

Table 3-4 PL/SQL: DBMS_LOB Procedures to Modify BLOB, CLOB, and NCLOB Values
Function/Procedure Description

APPEND()

Appends the LOB value to another LOB

COPY()

Copies all or part of a LOB to another LOB

ERASE()

Erases part of a LOB, starting at a specified offset

LOADFROMFILE()

Load BFILE data into an internal LOB

LOADCLOBFROMFILE()

Load character data from a file into a LOB

LOADBLOBFROMFILE()

Load binary data from a file into a LOB

TRIM()

Trims the LOB value to the specified shorter length

WRITE()

Writes data to the LOB at a specified offset

WRITEAPPEND()

Writes data to the end of the LOB

PL/SQL Functions/Procedures To Read or Examine Internal and External
LOB Values

Table 3-5  PL/SQL: DBMS_LOB Procedures to Read or Examine Internal and External LOB values
Function/Procedure Description

COMPARE()

Compares the value of two LOBs

GETCHUNKSIZE()

Gets the chunk size used when reading and writing. This only works on internal LOBs and does not apply to external LOBs (BFILEs).

GETLENGTH()

Gets the length of the LOB value

INSTR()

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

READ()

Reads data from the LOB starting at the specified offset

SUBSTR()

Returns part of the LOB value starting at the specified offset

PL/SQL Functions/Procedures To Operate on Temporary LOBs

Table 3-6 PL/SQL:  DBMS_LOB Procedures to Operate on Temporary LOBs
Function/Procedure Description

CREATETEMPORARY()

Creates a temporary LOB

ISTEMPORARY()

Checks if a LOB locator refers to a temporary LOB

FREETEMPORARY()

Frees a temporary LOB

PL/SQL Read-Only Functions/Procedures for BFILEs

Table 3-7  PL/SQL: DBMS_LOB Read-Only Procedures for BFILEs
Function/Procedure Description

FILECLOSE()

Closes the file. Use CLOSE() instead.

FILECLOSEALL()

Closes all previously opened files

FILEEXISTS()

Checks if the file exists on the server

FILEGETNAME()

Gets the directory alias and file name

FILEISOPEN()

Checks if the file was opened using the input BFILE locators. Use ISOPEN() instead.

FILEOPEN()

Opens a file. Use OPEN() instead.

PL/SQL Functions/Procedures To Open and Close Internal and External LOBs

Table 3-8   PL/SQL: DBMS_LOB Procedures to Open and Close Internal and External LOBs
Function/Procedure Description

OPEN()

Opens a LOB

ISOPEN()

Sees if a LOB is open

CLOSE()

Closes a LOB

These procedures are described in detail for specific LOB operations, such as, INSERT a row containing a LOB, in these chapters:

You can access many of the PL/SQL LOB example scripts from these chapters, at $ORACLE_HOME/rdbms/demo/lobs/plsql.

Using C (OCI) To Work With LOBs

Oracle Call Interface (OCI) can be used to make changes to an entire internal LOB, or to pieces of the beginning, middle or end of it through OCI, as follows:

OCI also includes functions that you can use to:

These functions are listed in the following tables, and are discussed in greater detail later in this section.

Set CSID Parameter To OCI_UCS2ID to Read/Write in UCS2

If you want to read or write data in 2 byte unicode (UCS2) format, set the csid (character set ID) parameter in OCILobRead and OCILobWrite to OCI_UCS2ID. The csid parameter indicates the character set id for the buffer parameter. You can set the csid parameter to any character set ID. If the csid parameter is set, it will override the NLS_LANG environment variable.

See Also:

Offset and Amount Parameters: Fixed-Width Versus Varying-Width,
Character or Byte

Fixed Width Character Set Rules

In OCI, for fixed-width client-side character sets, the following rules apply:

Varying-Width Character Set Rules

The following rules apply only to varying-width client-side character sets:

Other Operations

For all other LOB operations, irrespective of the client-side character set, the amount parameter is in characters for CLOBs and NCLOBs. These include OCILobCopy, OCILobErase, OCILobLoadFromFile, and OCILobTrim. All these operations refer to the amount of LOB data on the server.

See also:

Oracle9i Database Globalization Support Guide

NCLOBs

NCLOBs parameters are allowed in methods.

OCILobLoadFromFile: Specify Amount Parameter to be Less than Length of BFILE

When using OCILobLoadFromFile you cannot specify amount larger than the length of the BFILE.

OCILobRead: Specify Amount Parameter to be 4 gigabytes - 1

In OCILobRead, you can specify amount = 4 gigabytes-1, and it will read to the end of the LOB.

OCI LOB Examples

Further OCI examples are provided in:

You can access most of the OCI LOB example scripts from your Oracle9i distribution software at $ORACLE_HOME/rdbms/demo/lobs/oci.

There are further example OCI scripts:

See also Appendix B, "OCI Demonstration Programs" in Oracle Call Interface Programmer's Guide, for further OCI demonstration script listings.

Further Information About OCI

For further information and features of OCI, refer to the OTN Web site, http://otn.oracle.com/ for OCI features and FAQs.

OCI Functions that Operate on BLOBs, BLOBs, NCLOBs, and BFILEs

OCI functions that operate on BLOBs, CLOBs, NCLOBs, and BFILEs are as follows:

OCI Functions To Modify Internal LOB (BLOB, CLOB, and NCLOB) Values

Table 3-9 OCI Functions To Modify Internal LOB (BLOB, CLOB, and NCLOB) Values 
Function/Procedure Description

OCILobAppend()

Appends LOB value to another LOB.

OCILobCopy()

Copies all or part of a LOB to another LOB.

OCILobErase()

Erases part of a LOB, starting at a specified offset.

OCILobLoadFromFile()

Loads BFILE data into an internal LOB.

OCILobTrim()

Truncates a LOB.

OCILobWrite()

Writes data from a buffer into a LOB, overwriting existing data.

OCILobWriteAppend()

Writes data from a buffer to the end of the LOB.

OCI Functions To Read or Examine Internal LOB and External LOB (BFILE) Values

Table 3-10 OCI Functions To Read or Examine internal LOB and external LOB (BFILE) Values
Function/Procedure Description

OCILobGetChunkSize()

Gets the Chunk size used when reading and writing. This works on internal LOBs and does not apply to external LOBs (BFILEs).

OCILobGetLength()

Returns the length of a LOB or a BFILE.

OCILobRead()

Reads a specified portion of a non-null LOB or a BFILE into a buffer.

OCI Functions For Temporary LOBs

Table 3-11  OCI Functions for Temporary LOBs
Function/Procedure Description

OCILobCreateTemporary()

Creates a temporary LOB

OCILobIsTemporary()

Sees if a temporary LOB exists

OCILobFreeTemporary()

Frees a temporary LOB

OCI Read-Only Functions For BFILEs

Table 3-12 OCI Read-Only Functions for BFILES  
Function/Procedure Description

OCILobFileClose()

Closes an open BFILE.

OCILobFileCloseAll()

Closes all open BFILEs.

OCILobFileExists()

Checks whether a BFILE exists.

OCILobFileGetName()

Returns the name of a BFILE.

OCILobFileIsOpen()

Checks whether a BFILE is open.

OCILobFileOpen()

Opens a BFILE.

OCI LOB Locator Functions

Table 3-13  OCI LOB-Locator Functions
Function/Procedure Description

OCILobAssign()

Assigns one LOB locator to another.

OCILobCharSetForm()

Returns the character set form of a LOB.

OCILobCharSetId()

Returns the character set ID of a LOB.

OCILobFileSetName()

Sets the name of a BFILE in a locator.

OCILobIsEqual()

Checks whether two LOB locators refer to the same LOB.

OCILobLocatorIsInit()

Checks whether a LOB locator is initialized.

OCI LOB-Buffering Functions

Table 3-14  OCI LOB-Buffering Functions
Function/Procedure Description

OCILobDisableBuffering()

Disables the buffering subsystem use.

OCILobEnableBuffering()

Uses the LOB buffering subsystem for subsequent reads and writes of LOB data.

OCILobFlushBuffer()

Flushes changes made to the LOB buffering subsystem to the database (server)

OCI Functions To Open and Close Internal and External LOBs

Table 3-15  OCI Functions To Open and Close Internal and External LOBs
Function/Procedure Description

OCILobOpen()

Opens a LOB

OCILobIsOpen()

Sees if a LOB is open

OCILobClose()

Closes a LOB

OCI Example -- Is the LOB Open: main() and seeIfLOBIsOpen

To work with the OCI examples in the remainder of the book, you can use a main() like the following. Here, it is used with seeIfLOBIsOpen as an example.

int main(char *argv, int argc)
{
 /* Declare OCI Handles to be used */
  OCIEnv        *envhp;
  OCIServer     *srvhp; 
  OCISvcCtx     *svchp;
  OCIError      *errhp;
  OCISession    *authp;
  OCIStmt       *stmthp;
  OCILobLocator *Lob_loc;

 /* Create and Initialize an OCI Environment: */
  (void) OCIEnvCreate(&envhp, (ub4)OCI_DEFAULT, (dvoid *)0,
                      (dvoid * (*)(dvoid *, size_t)) 0,
                      (dvoid * (*)(dvoid *, dvoid *, size_t))0,
                      (void (*)(dvoid *, dvoid *))0,
                      (size_t) 0, (dvoid **) 0);

 /* Allocate error handle: */
  (void) OCIHandleAlloc((dvoid *) envhp, (dvoid **) &errhp, OCI_HTYPE_ERROR, 
                        (size_t) 0, (dvoid **) 0);

 /* Allocate server contexts: */
  (void) OCIHandleAlloc((dvoid *) envhp, (dvoid **) &srvhp, OCI_HTYPE_SERVER,
                        (size_t) 0, (dvoid **) 0);

 /* Allocate service context: */
  (void) OCIHandleAlloc((dvoid *) envhp, (dvoid **) &svchp, OCI_HTYPE_SVCCTX,
                        (size_t) 0, (dvoid **) 0);

 /* Attach to the Oracle database:  */
  (void) OCIServerAttach(srvhp, errhp, (text *)"", strlen(""), 0);

 /* Set the server context attribute in the service context: */
  (void) OCIAttrSet ((dvoid *) svchp, OCI_HTYPE_SVCCTX, 
                     (dvoid *)srvhp, (ub4) 0,
                     OCI_ATTR_SERVER, (OCIError *) errhp);

 /* Allocate the session handle: */
  (void) OCIHandleAlloc((dvoid *) envhp, 
                        (dvoid **)&authp, (ub4) OCI_HTYPE_SESSION,
                        (size_t) 0, (dvoid **) 0);
 
 /* Set the username in the session handle:*/
  (void) OCIAttrSet((dvoid *) authp, (ub4) OCI_HTYPE_SESSION,
                    (dvoid *) "samp", (ub4)4,
                    (ub4) OCI_ATTR_USERNAME, errhp);
 /* Set the password in the session handle: */
  (void) OCIAttrSet((dvoid *) authp, (ub4) OCI_HTYPE_SESSION,
                    (dvoid *) "samp", (ub4) 4,
                    (ub4) OCI_ATTR_PASSWORD, errhp);

 /* Authenticate and begin the session: */
  checkerr(errhp, OCISessionBegin (svchp,  errhp, authp, OCI_CRED_RDBMS, 
                                   (ub4) OCI_DEFAULT));

 /* Set the session attribute in the service context: */
  (void) OCIAttrSet((dvoid *) svchp, (ub4) OCI_HTYPE_SVCCTX,
                    (dvoid *) authp, (ub4) 0,
                   (ub4) OCI_ATTR_SESSION, errhp);

 /* ------- At this point a valid session has been created -----------*/
  printf ("user session created \n");

 /* Allocate a statement handle: */
  checkerr(errhp, OCIHandleAlloc( (dvoid *) envhp, (dvoid **) &stmthp,
           OCI_HTYPE_STMT, (size_t) 0, (dvoid **) 0));

 /* =============  Sample procedure call begins here ===================*/  

  printf ("calling seeIfLOBIsOpen...\n");
  seeIfLOBIsOpen(envhp, errhp, svchp, stmthp);

  return 0;
}

void checkerr(errhp, status)
OCIError *errhp;
sword status;
{
  text errbuf[512];
  sb4 errcode = 0;

  switch (status)
  {
  case OCI_SUCCESS:
    break;
  case OCI_SUCCESS_WITH_INFO:
    (void) printf("Error - OCI_SUCCESS_WITH_INFO\n");
    break;
  case OCI_NEED_DATA:
    (void) printf("Error - OCI_NEED_DATA\n");
    break;
  case OCI_NO_DATA:
    (void) printf("Error - OCI_NODATA\n");
    break;
  case OCI_ERROR:
    (void) OCIErrorGet((dvoid *)errhp, (ub4) 1, (text *) NULL, &errcode,
                        errbuf, (ub4) sizeof(errbuf), OCI_HTYPE_ERROR);
    (void) printf("Error - %.*s\n", 512, errbuf);
    break;
  case OCI_INVALID_HANDLE:
    (void) printf("Error - OCI_INVALID_HANDLE\n");
    break;
  case OCI_STILL_EXECUTING:
    (void) printf("Error - OCI_STILL_EXECUTE\n");
    break;
  case OCI_CONTINUE:
    (void) printf("Error - OCI_CONTINUE\n");
    break;
  default:
    break;
  }
}

/* Select the locator into a locator variable */

sb4 select_frame_locator(Lob_loc, errhp, svchp, stmthp)
OCILobLocator *Lob_loc;
OCIError      *errhp;
OCISvcCtx     *svchp;
OCIStmt       *stmthp;     
{
  text      *sqlstmt = 
                 (text *)"SELECT Frame FROM Multimedia_tab WHERE Clip_ID=1";
  OCIDefine *defnp1;

  checkerr (errhp, OCIStmtPrepare(stmthp, errhp, sqlstmt, 
                                  (ub4)strlen((char *)sqlstmt),
                                  (ub4) OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT));
  
  checkerr (errhp, OCIDefineByPos(stmthp, &defnp1, errhp, (ub4) 1,
                                  (dvoid *)&Lob_loc, (sb4)0, 
                                  (ub2) SQLT_BLOB,(dvoid *) 0, 
                                  (ub2 *) 0, (ub2 *) 0, (ub4) OCI_DEFAULT));

  /* execute the select and fetch one row */
  checkerr(errhp, OCIStmtExecute(svchp, stmthp, errhp, (ub4) 1, (ub4) 0,
                                 (CONST OCISnapshot*) 0, (OCISnapshot*) 0,  
                                 (ub4) OCI_DEFAULT));
  
  return (0);
}

void seeIfLOBIsOpen(envhp, errhp, svchp, stmthp)
OCIEnv    *envhp;
OCIError  *errhp;
OCISvcCtx *svchp;
OCIStmt   *stmthp;
{
  OCILobLocator *Lob_loc;
  int isOpen;

  /* allocate locator resources */
  (void) OCIDescriptorAlloc((dvoid *)envhp, (dvoid **)&Lob_loc,
                            (ub4)OCI_DTYPE_LOB, (size_t)0, (dvoid **)0);

  /* Select the locator */
  (void)select_frame_locator(Lob_loc, errhp, svchp, stmthp);
  
  /* See if the LOB is Open */
  checkerr (errhp, OCILobIsOpen(svchp, errhp, Lob_loc, &isOpen));
 
  if (isOpen)
  {
    printf("  Lob is Open\n");
    /* ... Processing given that the LOB has already been Opened */
  }
  else
  {
    printf("  Lob is not Open\n");
    /* ... Processing given that the LOB has not been Opened */
  }

  /* Free resources held by the locators*/
  (void) OCIDescriptorFree((dvoid *) Lob_loc, (ub4) OCI_DTYPE_LOB);
    return;
}

Using C++ (OCCI) To Work With LOBs

Oracle C++ Call Interface (OCCI) is a C++ API for manipulating data in an Oracle database. OCCI is organized as an easy-to-use collection of C++ classes which enable a C++ program to connect to a database, execute SQL statements, insert/update values in database tables, retrieve results of a query, execute stored procedures in the database, and access metadata of database schema objects. OCCI also provides a seamless interface to manipulate objects of user-defined types as C++ class instances.

Oracle C++ Call Interface (OCCI) is designed so that you can use OCI and OCCI together to build applications.

The OCCI API provides the following advantages over JDBC and ODBC:

You can use Oracle C++ Call Interface (OCCI) to make changes to an entire internal LOB, or to pieces of the beginning, middle, or end of it, as follows:

Distinct Classes for Each LOB Type

Unlike OCI which uses a common API for operations on BLOBs, CLOBs, and BFILEs, OCCI has distinct classes for each LOB types, as follows:

OCCIClob Class

The OCCIClob driver implements a CLOB object using an SQL locator(CLOB). This means that a CLOB object contains a logical pointer to the SQL CLOB data rather than the data itself.

The CLOB interface provides methods for getting the length of an SQL CLOB (Character Large Object) value, for materializing a CLOB value on the client, and getting a substring. Methods in the interfaces ResultSet statement such as getClob() and setClob() allow you to access SQL CLOB values.

OCCIBlob Class

Methods in the OCCIResultSet and OCCIStatement interfaces, such as getBlob() and setBlob(), allow you to access SQL BLOB values. The OCCIBlob interface provides methods for getting the length of a SQL BLOB value, for materializing a BLOB value on the client, and for extracting a part of the BLOB.

These methods are listed in the following tables.

See Also:

Offset and Amount Parameters: Fixed-Width Versus Varying-Width,
Character or Byte

Fixed Width Character Set Rules

In OCCI, for fixed-width client-side character sets, the following rules apply:

Varying-Width Character Set Rules

The following rules apply only to varying-width client-side character sets:

OffSet and Amount Parameters for Other OCCI Operations

For all other OCCI LOB operations, irrespective of the client-side character set, the amount parameter is in characters for CLOBs and NCLOBs. These include the following:

All these operations refer to the amount of LOB data on the server.

See also:

Oracle9i Database Globalization Support Guide

NCLOBs

Loading from Files with OCCIClob.copy() and OCCIBlob.copy(): Amount Parameter

The LoadFromFile functionality in OCCI is provided though the OCCIClob.copy() and OCCIBlob.copy() methods. These take an OCCIBfile argument.

You cannot specify amounts larger than the length of the BFILE. You must specify an amount parameter less than length of the BFILE.

OCCIClob.read(), OCCIBlob.read(), and OCCIBfile.read():Amount Parameter

When reading in OCCIClobs, OCCIBlobs, and OCCIBfiles, specify the amount = 4 gigabytes-1, and it will read to the end of the LOB.

Further Information About OCCI

See Also:

OCCI Methods that Operate on BLOBs, BLOBs, NCLOBs, and BFILEs

OCCI methods that operate on BLOBs, CLOBs, NCLOBs, and BFILEs are as follows:

OCCI Methods To Modify Internal LOB (BLOB, CLOB, and NCLOB) Values

Table 3-16 OCCI Clob and OCCIBlob Methods To Modify Internal LOB (BLOB, CLOB, and NCLOB) Values
Function/Procedure Description

OCCIBlob.append()

Appends CLOB or BLOB valu