skip to main content
Functions : Scalar functions : CONVERT
 

CONVERT

Syntax 

CONVERT (value_exp, data_type)

Description

The function returns the value specified by value_exp converted to the specified data type, where data_type is one of the following keywords:
SQL_BIGINT
SQL_BINARY
SQL_BIT
SQL_CHAR
SQL_DATE
SQL_DECIMAL
SQL_DOUBLE
SQL_FLOAT
SQL_INTEGER
SQL_LONGVARCHAR
SQL_LONGVARBINARY
SQL_NUMERIC
SQL_REAL
SQL_SMALLINT
SQL_TIME
SQL_TIMESTAMP
SQL_TINYINT
SQL_VARBINARY
SQL_VARCHAR
SQL_WCHAR
SQL_WVARCHAR
SQL_WLONGVARCHAR
The following table defines the precision, length, and scale of the resulting expression.
Table 16: Length, precision, and scale keywords of the CONVERT function 
Keyword
Length
Precision
Scale
SQL_BIGINT
8
20
0
SQL_CHAR
256
255
0
SQL_BINARY
256
255
0
SQL_BIT
1
1
0
SQL_DATE
6
10
0
SQL_DOUBLE
8
15
0
SQL_FLOAT
8
15
0
SQL_INTEGER
4
10
0
SQL_LONGVARBINARY
1000000
1000000
0
SQL_LONGVARCHAR
1000000
1000000
0
SQL_NUMERIC
32
34
5
SQL_SMALLINT
2
5
0
SQL_REAL
4
7
0
SQL_TIME
6
8
0
SQL_TIMESTAMP
16
 
0
SQL_TINYINT
1
3
0
SQL_VARBINARY
1024
1024
0
SQL_VARCHAR
1024
1024
0
SQL_WLONGVARCHAR
2000000
1000000
0
SQL_WVARCHAR
2048
1024
0
SQL_WCHAR
255
255
0
SQL_WVARCHAR
2048
1024
0

Example 

SELECT empno, CONVERT(empno, SQL_VARCHAR) FROM emp
SELECT empno, CONVERT(empno, SQL_SMALLINT) FROM emp