Application Development Guide


Supported SQL Data Types in FORTRAN

Certain predefined FORTRAN data types correspond to database manager column types. Only these FORTRAN data types can be declared as host variables.

Table 34 shows the FORTRAN equivalent of each column type. When the precompiler finds a host variable declaration, it determines the appropriate SQL type value. The database manager uses this value to convert the data exchanged between the application and itself.
Note:There is no host variable support for the DATALINK data type in any of the DB2 host languages.

Table 34. SQL Data Types Mapped to FORTRAN Declarations
SQL Column Type1 FORTRAN Data Type SQL Column Type Description

SMALLINT
(500 or 501)

INTEGER*2 16-bit, signed integer

INTEGER
(496 or 497)

INTEGER*4 32-bit, signed integer

REAL2
(480 or 481)

REAL*4 Single precision floating point

DOUBLE3
(480 or 481)

REAL*8 Double precision floating point

DECIMAL(p,s)
(484 or 485)

No exact equivalent; use REAL*8 Packed decimal

CHAR(n)
(452 or 453)

CHARACTER*n Fixed-length character string of length n where n is from 1 to 254

VARCHAR(n)
(448 or 449)

SQL TYPE IS VARCHAR(n) where n is from 1 to 32 672 Variable-length character string

LONG VARCHAR
(456 or 457)

SQL TYPE IS VARCHAR(n) where n is from 32 673 to 32 700 Long variable-length character string

CLOB(n)
(408 or 409)

SQL TYPE IS CLOB (n) where n is from 1 to 2 147 483 647 Large object variable-length character string

CLOB locator variable4
(964 or 965)

SQL TYPE IS CLOB_LOCATOR Identifies CLOB entities residing on the server

CLOB file reference variable4
(920 or 921)

SQL TYPE IS CLOB_FILE Descriptor for file containing CLOB data

BLOB(n)
(404 or 405)

SQL TYPE IS BLOB(n) where n is from 1 to 2 147 483 647 Large object variable-length binary string

BLOB locator variable4
(960 or 961)

SQL TYPE IS BLOB_LOCATOR Identifies BLOB entities on the server

BLOB file reference variable4
(916 or 917)

SQL TYPE IS BLOB_FILE Descriptor for the file containing BLOB data

DATE
(384 or 385)

CHARACTER*10 10-byte character string

TIME
(388 or 389)

CHARACTER*8 8-byte character string

TIMESTAMP
(392 or 393)

CHARACTER*26 26-byte character string
Notes:
  1. The first number under SQL Column Type indicates that an indicator variable is not provided, and the second number indicates that an indicator variable is provided. An indicator variable is needed to indicate NULL values, or to hold the length of a truncated string. These are the values that would appear in the SQLTYPE field of the SQLDA for these data types.
  2. FLOAT(n) where 0 < n < 25 is a synonym for REAL. The difference between REAL and DOUBLE in the SQLDA is the length value (4 or 8).
  3. The following SQL types are synonyms for DOUBLE:
    • FLOAT
    • FLOAT(n) where 24 < n < 54 is
    • DOUBLE PRECISION
  4. This is not a column type but a host variable type.

The following is a sample SQL declare section with a host variable declared for each supported data type:

      EXEC SQL BEGIN DECLARE SECTION 
        INTEGER*2     AGE  /26/ 
        INTEGER*4     DEPT 
        REAL*4        BONUS
        REAL*8        SALARY 
        CHARACTER     MI 
        CHARACTER*112 ADDRESS 
        SQL TYPE IS VARCHAR (512) DESCRIPTION 
        SQL TYPE IS VARCHAR (32000) COMMENTS
        SQL TYPE IS CLOB (1M) CHAPTER
        SQL TYPE IS CLOB_LOCATOR CHAPLOC 
        SQL TYPE IS CLOB_FILE  CHAPFL 
        SQL TYPE IS BLOB (1M) VIDEO 
        SQL TYPE IS BLOB_LOCATOR VIDLOC 
        SQL TYPE IS BLOB_FILE VIDFL 
        CHARACTER*10  DATE 
        CHARACTER*8   TIME 
        CHARACTER*26  TIMESTAMP 
        INTEGER*2     WAGE_IND 
      EXEC SQL END DECLARE SECTION 

The following are additional rules for supported FORTRAN data types:


[ Top of Page | Previous Page | Next Page ]