Example: Using a locator to work with a CLOB value
Suppose that you want your application program to retrieve a locator for a large object (LOB) value and then use the locator to extract 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
- 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.
- 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.
- 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 the first example, the C language is used so check_error is redefined as CHECKERR and is located in the util.c file.
- Example: LOBLOC.SQC in C
This example program written in C uses a locator to retrieve a LOB value.
- Example: LOBLOC.SQB in COBOL
This example program written in COBOL uses a locator to retrieve a LOB value.
Parent topic:
Large objects
Related concepts
Large object locators