Performing assignments involving distinct types in dynamic SQL

This section describes how to perform assignments involving distinct types in dynamic SQL

About this task

Suppose you want to store the job application form completed by a new applicant into the database. You have defined a host variable containing the character string value used to represent the completed form. To use dynamic SQL, you can use parameter markers as follows:
     EXEC SQL BEGIN DECLARE SECTION; 
       long id; 
       char name[30]; 
       SQL TYPE IS CLOB(32K) form; 
       char command[80]; 
     EXEC SQL END DECLARE SECTION; 
  
     /* Code to fill host variables */ 
  
     strcpy(command,"INSERT INTO APPLICATIONS VALUES"); 
     strcat(command,"(?, ?, CURRENT DATE, CAST (? AS CLOB(32K)))"); 
  
     EXEC SQL PREPARE APP_INSERT FROM :command; 
     EXEC SQL EXECUTE APP_INSERT USING :id, :name, :form;
This makes use of the cast specification to tell Db2® that the type of the parameter marker is CLOB(32K), a type that is assignable to the distinct type column. Remember that you cannot declare a host variable of a distinct type, since host languages do not support distinct types. Therefore, you cannot specify that the type of a parameter marker is a distinct type.