Equivalent SQL and assembler data types
When you declare host variables in your assembler programs, the precompiler uses equivalent SQL data types. When you retrieve data of a particular SQL data type into a host variable, ensure that the host variable is of an equivalent data type.
The following table describes the SQL data type and the base SQLTYPE and SQLLEN values that the precompiler uses for host variables in SQL statements.
Assembler host variable data type | SQLTYPE of host variable1 | SQLLEN of host variable | SQL data type |
---|---|---|---|
|
500 | 2 |
|
|
496 | 4 |
|
|
484 | p in byte 1, s in byte 2 |
|
short decimal FLOAT:
|
996 | 4 |
|
long decimal FLOAT:
|
996 | 8 |
|
extended decimal FLOAT:
|
996 | 16 |
|
|
480 | 4 |
|
|
480 | 8 |
|
|
492 | 8 |
|
|
912 | n |
|
|
908 | n |
|
|
452 | n |
|
|
448 | n |
|
|
456 | n |
|
2 |
468 | n |
3 |
2 |
464 | n |
3 |
2 |
472 | n |
3 |
|
972 | 4 |
|
|
976 | 4 |
|
|
960 | 4 |
|
|
964 | 4 |
|
|
968 | 4 |
|
|
404 | n |
|
|
408 | n |
|
|
412 | n |
3 |
|
404 | 0 |
|
|
408 | 0 |
|
|
412 | 0 |
|
|
916/917 | 267 |
|
|
920/921 | 267 |
|
|
924/925 | 267 |
|
|
916/917 | 267 |
|
|
920/921 | 267 |
|
|
924/925 | 267 |
|
|
904 | 40 |
|
Notes:
|
The following table shows equivalent assembler host variables for each SQL data type. Use this table to determine the assembler data type for host variables that you define to receive output from the database. For example, if you retrieve TIMESTAMP data, you can define variable DS CLn.
This table shows direct conversions between SQL data types and assembler data types. However, a number of SQL data types are compatible. When you do assignments or comparisons of data that have compatible data types, DB2® converts those compatible data types.
SQL data type | Assembler host variable equivalent | Notes |
---|---|---|
SMALLINT | DS HL2 | |
INTEGER | DS F | |
BIGINT | DS FD OR DS FDL8 | DS FDL8 requires High Level Assembler (HLASM), Release 4 or later. |
DECIMAL(p,s) or NUMERIC(p,s) | DS P'value' DS PLn'value' DS PLn | p is precision; s is scale. 1<=p<=31 and 0<=s<=p. 1<=n<=16. value is a literal value that includes a decimal point. You must use Ln, value, or both. Using only value is recommended. Precision: If you use Ln, it is 2n-1; otherwise, it is the number of digits in value. Scale: If you use value, it is the number of digits to the right of the decimal point; otherwise, it is 0. For efficient use of indexes: Use value. If p is even, do not use Ln and be sure the precision of value is p and the scale of value is s. If p is odd, you can use Ln (although it is not advised), but you must choose n so that 2n-1=p, and value so that the scale is s. Include a decimal point in value, even when the scale of value is 0. |
REAL or FLOAT(n) | DS EL4 DS EHL4 DS EBL41 | 1<=n<=21 |
DOUBLE PRECISION, DOUBLE, or FLOAT(n) | DS DL8 DS DHL8 DS DBL81 | 22<=n<=53 |
DECFLOAT | DC EDL4 DC DDL8 DC LDL16 | |
CHAR(n) | DS CLn | 1<=n<=255 |
VARCHAR(n) | DS HL2,CLn | |
GRAPHIC(n) | DS GLm | m is expressed in bytes. n is the number of double-byte characters. 1<=n<=127 |
VARGRAPHIC(n) | DS HL2,GLx DS HL2'm',GLx'<value>' | x and m are expressed in bytes. n is the number of double-byte characters. < and > represent shift-out and shift-in characters. |
BINARY(n) |
|
1<=n<=255 |
VARBINARY(n) |
|
1<=n<=32704 |
DATE | DS CLn | If you are using a date exit routine, n is determined by that routine; otherwise, n must be at least 10. |
TIME | DS CLn | If you are using a time exit routine, n is determined by that routine. Otherwise, n must be at least 6; to include seconds, n must be at least 8. |
TIMESTAMP | DS CLn | n must be at least 19. To include microseconds, n must be 26; if n is less than 26, truncation occurs on the microseconds part. |
TIMESTAMP(0) | DS CLn | n must be at least 19. |
TIMESTAMP(p) p > 0 | DS CLn | n must be at least 19. To include fractional seconds, n must be 20+x where x is the number of fractional seconds to include; if x is less than p, truncation occurs on the fractional seconds part. |
TIMESTAMP(0) WITH TIME ZONE | DS HL2,CLn | n must be at least 25. |
TIMESTAMP(p) WITH TIME ZONE p > 0 | DS HL2,CLn | n must be at least 26+p. |
Result set locator | DS F | Use this data type only to receive result sets. Do not use this data type as a column type. |
Table locator | SQL TYPE IS TABLE LIKE table-name AS LOCATOR | Use this data type only in a user-defined function or stored procedure to receive rows of a transition table. Do not use this data type as a column type. |
BLOB locator | SQL TYPE IS BLOB_LOCATOR | Use this data type only to manipulate data in BLOB columns. Do not use this data type as a column type. |
CLOB locator | SQL TYPE IS CLOB_LOCATOR | Use this data type only to manipulate data in CLOB columns. Do not use this data type as a column type. |
DBCLOB locator | SQL TYPE IS DBCLOB_LOCATOR | Use this data type only to manipulate data in DBCLOB columns. Do not use this data type as a column type. |
BLOB(n) | SQL TYPE IS BLOB(n) | 1≤n≤2147483647 |
CLOB(n) | SQL TYPE IS CLOB(n) | 1≤n≤2147483647 |
DBCLOB(n) | SQL TYPE IS DBCLOB(n) | n is the number of double-byte characters. 1≤n≤1073741823 |
XML | SQL TYPE IS XML AS BLOB(n) | 1≤n≤2147483647 |
XML | SQL TYPE IS XML AS CLOB(n) | 1≤n≤2147483647 |
XML | SQL TYPE IS XML AS DBCLOB(n) | n is the number of double-byte characters. 1≤n≤1073741823 |
BLOB file reference | SQL TYPE IS BLOB_FILE | Use this data type only to manipulate data in BLOB columns. Do not use this data type as a column type. |
CLOB file reference | SQL TYPE IS CLOB_FILE | Use this data type only to manipulate data in CLOB columns. Do not use this data type as a column type. |
DBCLOB file reference | SQL TYPE IS DBCLOB_FILE | Use this data type only to manipulate data in DBCLOB columns. Do not use this data type as a column type. |
XML BLOB file reference | SQL TYPE IS XML AS BLOB_FILE | Use this data type only to manipulate XML data as BLOB files. Do not use this data type as a column type. |
XML CLOB file reference | SQL TYPE IS XML AS CLOB_FILE | Use this data type only to manipulate XML data as CLOB files. Do not use this data type as a column type. |
XML DBCLOB file reference | SQL TYPE IS XML AS DBCLOB_FILE | Use this data type only to manipulate XML data as DBCLOB files. Do not use this data type as a column type. |
ROWID | SQL TYPE IS ROWID | |
Notes:
|