sql
  1. sql-char-function

Advanced SQL Topics: CHAR Function

Syntax

CHAR(integer_value)

Example

SELECT CHAR(65), CHAR(66), CHAR(67);

Output

CHAR(65) CHAR(66) CHAR(67)
A B C

Explanation

The CHAR function in SQL takes an integer value as an argument and returns the character value representing that particular Unicode code point. In the example above, integer values 65, 66, and 67 represent the Unicode code points of A, B, and C characters respectively. Hence, the output shows these three characters.

Use

The CHAR function is useful in scenarios where you need to fetch the character that corresponds to a specific Unicode code point. It can be used with other functions like ASCII and UNIODE to convert between character sets.

Important Points

  • The argument of CHAR must be an integer between 0 and 255.
  • If the argument is not an integer, it is rounded to the nearest integer before being evaluated.
  • If the argument is greater than 255 or less than 0, the CHAR function returns NULL.

Summary

The CHAR function in SQL is used to return the character that corresponds to a specific Unicode code point. Its argument must be an integer between 0 and 255. The function is commonly used in conjunction with other string manipulation functions to create complex expressions.

Published on: