The following articles mainly describe the type conversion functions of common DB2 functions. If you are interested in the type conversion functions described in common DB2 functions, you can click the following articles to view them, the following is a detailed description of the article.
Keywords: DB2, type conversion, Function
CAST expression used for Conversion Type
SQL code
- SELECT CAST(CURRENT TIME AS CHAR(8) ) FROM SYSIBM.SYSDUMMY1
- SELECT CAST(CURRENT TIME AS CHAR(8) ) FROM SYSIBM.SYSDUMMY1
Common DB2 functions: type conversion function 1. Convert to string type:
CHAR Function
Syntax: CHAR (ARG)
The CHAR function returns a string representation of a datetime, String, integer, decimal, or double-precision floating point number.
SQL code
- eg:
- SELECT CHAR(SALARY) FROM TEST
- eg:
- SELECT CHAR(SALARY) FROM TEST
CHR Function
Syntax: CHR (ARG)
The CHR function returns the ASCII code specified by the parameter. The parameter can be INTEGER or SMALLINT.
SQL code
- eg:
- SELECT CHR(167) FROM TEST
- eg:
- SELECT CHR(167) FROM TEST
Common DB2 functions-type conversion functions: VARCHAR Functions
Syntax: VARCHAR (ARG, LENGTH)
The VARCHAR function returns the variable-length string representation of the string, date type, and graphic string.
SQL code
- eg:
- SELECT VARCHAR(NAME,50) FROM TEST
-- 50 indicates the truncation length. If the length of the name string is greater than 50, "SQL0445W value has been truncated" is returned. SQLSTATE = 01004 ".
Eg:
- SELECT VARCHAR(NAME,50) FROM TEST
-- 50 indicates the truncation length. If the length of the name string is greater than 50, "SQL0445W value has been truncated" is returned. SQLSTATE = 01004 ".
DIGITS Function
Syntax: DIGITS ()
The DIGITS function returns the string values of the SMALLINT, INTEGER, BIGIT, or DECIMAL parameters. SQL code
- eg:
- SELECT DIGITS(ID) FROM TEST
- eg:
- SELECT DIGITS(ID) FROM TEST
The above content is an introduction to the type conversion functions described in the common functions of DB2.