For information on UDFs with LOB input and return parameters, see Defining Functions that Use LOB Types.
When writing a scalar UDF that compresses BLOB or CLOB types, use the following general structure:
- Define a buffer size (no larger than 64KB) for reading portions of the source LOB.
- Use FNC_LobOpen to open reading of the source LOB.
- While more data exists in the LOB:
- Use FNC_LobRead to read a portion of the LOB into the allocated buffer.
- Perform the compression on the data in the buffer.
- If the UDF cannot compress the input string, return an SQLSTATE of 'U1005', otherwise, append the compressed contents of the buffer to the output LOB using FNC_LobAppend.
- Use FNC_LobClose to close reading of the source LOB.
- Handle errors reported by any FNC routines during processing.
- Release allocated resources once you have processed the data.
For information about the FNC functions, see LOB Access.
To see sample code for compressing CLOB data, see C Scalar Function for Compressing CLOB Data.