CHAR


The CHAR function returns a fixed-length character string representation of one of the following values:

  • An integer number if the first argument is a small, large, or big integer
  • A decimal number if the first argument is a decimal number
  • A floating-point number if the first argument is a single or double precision floating-point number
  • A decimal floating-point number if the first argument is a decimal floating-point number
  • A character string value if the first argument is any type of string
  • A date/time value if the first argument is a date, time, timestamp, or timestamp with time zone

Important

CHAR(numeric argument) is not supported for Index on Expression

 CHAR.png

The arguments are defined as follows:

integerExpression

integerExpression returns a value that is a built-in integer data type (SMALLINT, INTEGER, or BIGINT).

The result is the fixed-length character string representation of the argument in the form of an integer constant. The result consists of n characters that are the significant digits that represent the value of the argument. If the argument is negative, the result has a preceding minus sign.

The result is left justified. The result length must be 6 for a small integer, 11 for a large integer, and 20 for a big integer. Shorter results are padded on the right with blanks to achieve the required length

A positive value always includes one leading blank.

decimalExpression

decimalExpression returns a value that is a built-in decimal data type. The result is the fixed-length character string representation of the argument. The result includes a decimal point and up to p digits; p is the precision of the decimalExpression with the preceding minus sign if the argument is negative. If the number of bytes in the result is less than the defined length of the result, the result is padded on the right with blanks. The decimal point character is a period (.) or a comma (,) based on DSNHDECP specifications.

floatingExpression

floatingExpression returns a value that is a built-in floating-point data type (DOUBLE or REAL).

The result is the fixed-length character string representation of the argument in the form of a floating-point constant. The length of the result is 15 bytes for a short floating point and 23 for a long floating point in the following format:

+/-.mE+/-nn

/ denotes an OR condition, m represents mantissa, and represents an exponent.

decfloatExpression

decfloatExpression returns a value that is a built-in decimal floating data type (long or short).

The result is the fixed-length character string representation of the argument in the form of a floating-point constant. The length of the result is 34 bytes for a short decfloat and 42 for a long decfloat in the form of: +/-.mE+/-nnn and 42 bytes for a long floating point number in the following form:

+/-.mE+/-nnnn

/ denotes an OR condition, m represents mantissa, and n represents an exponent.

If the DECFLOAT value is one of the special values INFINITY, SNAN, or NAN, the strings INFINITY, SNAN, or NAN, respectively, are returned. If the special value is negative, a minus sign is the first character in the returned string.

stringExpression, length

stringExpression must be an expression that returns a value of a built-in character string whose length equals the value of the length argument.

The length value must be an integer constant not exceeding 255.

datetimeExpression, format

datetimeExpression, string

datetimeExpression must be an expression that is one of the following built-in data types:

  • DATE
  • TIME
  • TIMESTAMP
  • TIMESTAMP WITH TIMEZONE

The expression is converted to an external format using the format template, if applicable.

You must define the format as follows:

Expression type

Format type

DATE

ISO, USA ,EUR, JIS, LOCAL

If the format is not specified, it defaults to ISO.

Additional non-conventional formats can be specified in the form of a string of date format elements. Valid values are:

  • MM for month
  • DD for day
  • YY or YYYY for year

You can specify these elements in any order and can delimit them with any character, number, or series of characters or numbers. Although the process does not require a delimiter, it treats any other characters as constants in their specified position.

TIME

ISO, USA ,EUR, JIS, LOCAL

If the format is not specified, it defaults to ISO.

Additional non-conventional formats can be specified in the form of a string of time format elements. Valid values are:

  • HH for hour
  • MM for minute
  • SS for second
  • XM for AM or PM

You can specify these elements in any order and can delimit them with any character, number, or series of characters or numbers. Although the process does not require a delimiter, it treats any other characters as constants in their specified position.

TIMESTAMP WITHOUT TIMEZONE

The result is the character string representation of the timestamp. If datetimeExpression is a TIMESTAMP(0) value, the length of the result is 19. If datetimeExpression is a TIMESTAMP(integer) value, the length of the result is 20+ integer. Otherwise, the length of the result is 26.

The second argument of string may be specified with timestamp(6) as a formatting template that has date/time/microseconds elements. Valid values are:

  • MM for month
  • DD for day
  • YY or YYYY for year
  • HH for hour
  • MM for minute
  • SS for second
  • XM for AM or PM
  • NN for hundredths of a second
  • NNNN for milli-second
  • NNNNNN for a microsecond.

TIMEZONE WITH TIMEZONE

The result is the character string representation of the timestamp with time zone, formatted as yyyy-mm-ddhh.mm.ss.nnnnnn±th:tm with the appropriate number of n characters for the precision of the timestamp. If datetimeExpression is a TIMESTAMP (0) with timezone, the length of the result is 25.

If datetimeExpression is a TIMESTAMP(integer) with timezone, the length of the result is 26+ integer. The second argument must not be specified.

Important

If the argument can be null, the result can be null; if the argument's value is null, the result is the null value.


 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*