Oracle CHR Function

Oracle CHR Function

  • SQL
  • 1 min read

In Oracle, the CHR function returns the character that has the value equivalent to x in the database character set. CHR and ASCII are opposite functions. CHR returns the character given the character number and ASCII returns the character number given the character.

CHR Syntax

chr(x)

You can use this function in PL/SQL procedures and SQL statements. Below are some examples of CHR function:

Example 1:

select chr(97) a, chr(98) b, chr(99) c from dual;

Output:

ABC
abc

 

Example 2:

Get the next alphabet character for the given character. In the below example, I will pass the character 'd', and it will return the next alphabet character 'e':

select chr(ascii('d')+1) next_alphabet from dual;

Output:

NEXT_ALPHABET
e

 

See also: