Declaring scalar host variables

You must declare a scalar host variable with one of the following data attributes:

CHARACTER, GRAPHIC, or WIDECHAR
Host variables that are declared with the CHARACTER, GRAPHIC, or WIDECHAR attributes are called string host variables. The following restrictions apply to the string host variable:
  • It must have either the NONVARYING or VARYING attribute.
  • If it has the VARYING attribute, it must have the NATIVE attribute.
FIXED BINARY, FIXED DECIMAL, or FLOAT
Host variables that are declared with the FIXED and BINARY, FIXED and DECIMAL, or FLOAT attributes are called numeric host variables. The following restrictions apply to the numeric host variable:
  • It must have the REAL attribute.
  • If it has the FIXED and BINARY attributes, it must have the SIGNED and NATIVE attributes, a zero scale factor, and a precision greater than 7.
  • If it has the FIXED and DECIMAL attributes, it must have a nonnegative scale factor that is smaller than its precision.
  • If it has the FLOAT and DECIMAL attributes, it must have a precision that is less than 17 unless the FLOAT(DFP) option is in effect.
  • If it has the FLOAT and BINARY attributes, it must have a precision that is less than 54.
ORDINAL
Host variables that are declared with the ORDINAL attribute are also called numeric host variables. The following restrictions apply to these numeric host variables:
  • If SIGNED, it must have a precision greater than 7, and if UNSIGNED it must have a precision greater than 8.
  • It must have the NATIVE attribute.
SQL TYPE
Host variables that are declared with the SQL TYPE attribute are called SQL TYPE host variables. The attribute specification must conform to one of the following syntax diagrams:
BINARY
Read syntax diagramSkip visual syntax diagram
>>-SQL TYPE IS BINARY-(--length--)-----------------------------><

VARBINARY
Read syntax diagramSkip visual syntax diagram
>>-SQL TYPE IS VARBINARY-(--length--)--------------------------><

Result set locator
Read syntax diagramSkip visual syntax diagram
>>-SQL TYPE IS-RESULT_SET_LOCATOR------------------------------><

ROWID
Read syntax diagramSkip visual syntax diagram
>>-SQL TYPE IS-ROWID-------------------------------------------><

Table locator
Read syntax diagramSkip visual syntax diagram
>>-SQL TYPE IS TABLE LIKE--table-name--AS LOCATOR--------------><

LOB file reference
Read syntax diagramSkip visual syntax diagram
>>-SQL TYPE IS-+-BLOB_FILE---+---------------------------------><
               +-CLOB_FILE---+   
               '-DBCLOB_FILE-'   

LOB locator
Read syntax diagramSkip visual syntax diagram
>>-SQL TYPE IS--+-BLOB_LOCATOR---+-----------------------------><
                +-CLOB_LOCATOR---+   
                '-DBCLOB_LOCATOR-'   

LOB variable
Read syntax diagramSkip visual syntax diagram
>>-SQL TYPE IS-+-BLOB---+-(--length--+---+--)------------------><
               +-CLOB---+            +-K-+      
               '-DBCLOB-'            +-M-+      
                                     '-G-'      

BLOB
You can also use BINARY LARGE OBJECT as an alternative to BLOB.
CLOB
You can also use either CHARACTER LARGE OBJECT or CHAR LARGE OBJECT as an alternative to CLOB.
XML LOB variable
Read syntax diagramSkip visual syntax diagram
>>-SQL TYPE IS XML AS-+-BLOB---+-(--length--+---+--)-----------><
                      +-CLOB---+            +-K-+      
                      '-DBCLOB-'            +-M-+      
                                            '-G-'      

BLOB
You can also use BINARY LARGE OBJECT as an alternative to BLOB.
CLOB
You can also use either CHARACTER LARGE OBJECT or CHAR LARGE OBJECT as an alternative to CLOB.
XML file reference
Read syntax diagramSkip visual syntax diagram
>>-SQL TYPE IS XML AS---+-BLOB_FILE---+------------------------><
                        +-CLOB_FILE---+     
                        '-DBCLOB_FILE-'     

The following constant declarations are generated by the SQL preprocessor. You can use them to set the file option variable when you use the file reference host variables:
DCL SQL_FILE_READ      FIXED BIN(31) VALUE(2);
DCL SQL_FILE_CREATE    FIXED BIN(31) VALUE(8);
DCL SQL_FILE_OVERWRITE FIXED BIN(31) VALUE(16);
DCL SQL_FILE_APPEND    FIXED BIN(31) VALUE(32);





Published: 23 December 2018