Example: BLOB string search

In this example, you want the FINDSTRING function to work on BLOBs as well as on CLOBs. To do this, you define another FINDSTRING taking BLOB as the first parameter:

     CREATE FUNCTION FINDSTRING (BLOB(500K), VARCHAR(200)) 
       RETURNS INTEGER 
       CAST FROM FLOAT 
       SPECIFIC FINDSTRING_BLOB 
       EXTERNAL NAME 'MYLIB/MYPGM(FINDSTR)'
       LANGUAGE C 
       PARAMETER STYLE DB2SQL 
       NO SQL 
       DETERMINISTIC 
       NO EXTERNAL ACTION 
       RETURNS NULL ON NULL INPUT

This example illustrates overloading of the UDF name and shows that multiple UDFs can share the same program. Note that although a BLOB cannot be assigned to a CLOB, the same source code can be used. There is no programming problem in the above example as the interface for BLOB and CLOB between DB2® and the UDF program is the same: length followed by data.