Example: Use a locator to work with a CLOB value

In this example, the application program retrieves a locator for a LOB value; then it uses the locator to extract the data from the LOB value.

Using this method, the program allocates only enough storage for one piece of LOB data (the size is determined by the program). In addition, the program needs to issue only one fetch call using the cursor.

How the sample LOBLOC program works

  1. Declare host variables. The BEGIN DECLARE SECTION and END DECLARE SECTION statements delimit the host variable declarations. Host variables are prefixed with a colon (:) when referenced in an SQL statement. CLOB LOCATOR host variables are declared.
  2. Fetch the LOB value into the locator host variable. A CURSOR and FETCH routine is used to obtain the location of a LOB field in the database to a locator host variable.
  3. Free the LOB LOCATORS. The LOB LOCATORS used in this example are freed, releasing the locators from their previously associated values.

The CHECKERR macro/function is an error checking utility that is external to the program. The location of this error checking utility depends on the programming language that is used. In this example, C language is used so check_error is redefined as CHECKERR and is located in the util.c file.

Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.
Related concepts
Understand large object locators