Example: Using the LOB function to populate the database

Suppose that you populate your table by transferring your e-mail that is maintained in files into the Db2 for i database.

Run the following INSERT statement multiple times with different values of the HV_EMAIL_FILE until you have stored all your e-mail:

     EXEC SQL BEGIN DECLARE SECTION 
       SQL TYPE IS BLOB_FILE HV_EMAIL_FILE; 
  
     EXEC SQL END DECLARE SECTION 
       strcpy (HV_EMAIL_FILE.NAME, "/u/mail/email/mbox"); 
       HV_EMAIL_FILE.NAME_LENGTH = strlen(HV_EMAIL_FILE.NAME); 
       HV_EMAIL_FILE.FILE_OPTIONS = 2; 
  
     EXEC SQL INSERT INTO ELECTRONIC_MAIL 
       VALUES (CURRENT TIMESTAMP, :hv_email_file);

All the function provided by DB2® LOB support is applicable to UDTs whose source type are LOBs. Therefore, you have used LOB file reference variables to assign the contents of the file into the UDT column. You have not used the cast function to convert values of BLOB type into your e-mail type. This is because DB2 allows you to assign values of the source type of a distinct type to targets of the distinct type.