CHAR

Overview

The CHAR function is used to convert an integer (code) into the corresponding character. If the integer is within the ASCII range (i.e., less than or equal to 255), it is treated as an ASCII code and converted to the corresponding character; if the integer is greater than 255, it attempts to parse it as a Unicode code and convert it to the corresponding Unicode character. If the given integer cannot be represented as a valid Unicode character, it returns an empty character.

Syntax

CHAR(code)

Parameters

  • code: Integer, representing the character code to be converted.

Return Result

  • Returns a string, representing the converted character.

Usage Example

  1. Convert ASCII code to the corresponding character:
SELECT CHAR(ASCII('中')), LENGTH(CHAR(ASCII(''))), CHAR(ASCII('a'));

Result:

   中	1	a
  1. Convert Unicode code to corresponding character:
    SELECT CHAR(20013) AS result;

Result:

Conversion Result	In
  1. Convert Illegal Unicode Codes:
    SELECT CHAR(-1) AS result;

The result is empty

  1. Convert multiple character codes:
    SELECT CHAR(65), CHAR(66), CHAR(67) AS  ABC;

Result:

A	B	C

Notes

  • If the input integer exceeds the Unicode range, an empty character will be returned.
  • Please ensure that the input integer is a valid character code, otherwise it may result in incorrect results.