NCHR() Function in Oracle

In Oracle, the NCHR() function returns the character having the binary equivalent to its argument in the national character set.

It’s the equivalent of using the CHR() function with the USING NCHAR_CS argument.

Syntax

The syntax goes like this:

NCHR(number)

Where number is a NUMBER value, or any value that can be implicitly converted to NUMBER.

The value returned is always NVARCHAR2.

Example

Here’s a simple example to demonstrate:

SELECT NCHR(257)
FROM DUAL;

Result:

   NCHR(257) 
____________ 
ā           

Here I provided a number, and NCHR() returned the corresponding character in the national character set. In this case, the integer 257 maps to the character ā.

We can achieve the same result with the CHR() function when using the USING NCHAR_CS argument:

SELECT CHR (257 USING NCHAR_CS)
FROM DUAL;

Result:

   CHR(257USINGNCHAR_CS) 
________________________ 
ā                       

Null Values

Passing null returns null:

SET NULL 'null';

SELECT NCHR(null)
FROM DUAL;

Result:

   NCHR(NULL) 
_____________ 
null          

By default, SQLcl and SQL*Plus return a blank space whenever null occurs as a result of a SQL SELECT statement.

However, you can use SET NULL to specify a different string to be returned. Here I specified that the string null should be returned.

Incorrect Argument Count

Calling NCHR() without passing any arguments returns an error:

SELECT NCHR()
FROM DUAL;

Result:

Error starting at line : 1 in command -
SELECT NCHR()
FROM DUAL
Error at Command Line : 1 Column : 8
Error report -
SQL Error: ORA-00938: not enough arguments for function
00938. 00000 -  "not enough arguments for function"
*Cause:    
*Action:

And passing the wrong number of arguments results in an error:

SELECT NCHR(1, 2, 3)
FROM DUAL;

Result:

Error starting at line : 1 in command -
SELECT NCHR(1, 2, 3)
FROM DUAL
Error at Command Line : 1 Column : 19
Error report -
SQL Error: ORA-00939: too many arguments for function
00939. 00000 -  "too many arguments for function"
*Cause:    
*Action: