Example: Use LOB locators to manipulate UDT instances

Suppose you want to obtain information about a specific e-mail without having to transfer the entire e-mail into a host variable in your application program.

Remember that an e-mail can be quite large. Since your UDT is defined as a LOB, you can use LOB locators for that purpose:

     EXEC SQL BEGIN DECLARE SECTION 
       long hv_len; 
       char hv_subject[200]; 
       char hv_sender[200]; 
       char hv_buf[4096]; 
       char hv_current_time[26]; 
       SQL TYPE IS BLOB_LOCATOR hv_email_locator; 
     EXEC SQL END DECLARE SECTION 
  
     EXEC SQL SELECT MESSAGE 
       INTO :hv_email_locator 
       FROM ELECTRONIC MAIL 
       WHERE ARRIVAL_TIMESTAMP = :hv_current_time; 
  
     EXEC SQL VALUES (SUBJECT (E_MAIL(:hv_email_locator)) 
       INTO :hv_subject; 
     .... code that checks if the subject of the e_mail is relevant .... 
     .... if the e_mail is relevant, then............................... 
  
     EXEC SQL VALUES (SENDER (CAST (:hv_email_locator AS E_MAIL))) 
       INTO :hv_sender;

Because your host variable is of type BLOB locator (the source type of the UDT), you have explicitly converted the BLOB locator to your UDT, whenever it was used as an argument of a UDF defined on the UDT.