In an SQLJ program, you can create a distinct type using the CREATE DISTINCT TYPE statement in an executable clause.
You can also use CREATE TABLE in an executable clause to create a table that includes a column of that type. When you retrieve data from a column of that type, or update a column of that type, you use Java™ host variables or expressions with data types that correspond to the built-in types on which the distinct types are based.
String empNumVar;
int shoeSizeVar;
…
#sql [myConnCtx] {CREATE DISTINCT TYPE SHOESIZE AS INTEGER WITH COMPARISONS};
// Create distinct type
#sql [myConnCtx] {COMMIT}; // Commit the create
#sql [myConnCtx] {CREATE TABLE EMP_SHOE
(EMPNO CHAR(6), EMP_SHOE_SIZE SHOESIZE)};
// Create table using distinct type
#sql [myConnCtx] {COMMIT}; // Commit the create
#sql [myConnCtx] {INSERT INTO EMP_SHOE
VALUES('000010',6)}; // Insert a row in the table
#sql [myConnCtx] {COMMIT}; // Commit the INSERT
#sql [myConnCtx] {SELECT EMPNO, EMP_SHOE_SIZE
INTO :empNumVar, :shoeSizeVar
FROM EMP_SHOE}; // Retrieve the row
System.out.println("Employee number: " + empNumVar +
" Shoe size: " + shoeSizeVar);