CHAR converts a value to CHAR.

Syntax

CHAR ( convExpression [, charLength ] )

Arguments

  • convExpression: A value to convert to CHAR.
    • convExpression can evaluate to a CHAR, VARCHAR, LONG VARCHAR, DATE, TIME, TIMESTAMP, DECIMAL, DOUBLE, REAL, SMALLINT, INTEGER, or BIGINT.
  • charLength: Include only when convExpression is a string type.
    • Defines the length for the returned CHAR value.
    • Values that are shorter than charLength will be padded with spaces to be charLength.
    • charLength should be an integer between 1 (default) and 254, inclusive, which is the number of bytes.

Returns

convExpression is… Returns Size
String type Fixed width CHAR value with maximum size of charSize. n/a
date or time type Character expression for the value, with size based on the input type. DATE=10

TIME=8

TIMESTAMP=26.
integer value SQL integer constant with size based on the integer type. SMALLINT-=6

INTEGER=11

BIGINT=20
NULL NULL n/a

Examples

VALUES CHAR('2012-06-20');
--Returns
2012-06-20