Oracle UNISTR() Function

Oracle UNISTR() is a built-in function that returns the given character data in the national character set.

The national character set of the database can be either AL16UTF16 or UTF8. UNISTR provides support for Unicode string literals, allowing you to specify the Unicode code point values for characters in a string.

The format for Unicode code point values is '\xxxx', where 'xxxx' is the hexadecimal value of the character in UCS-2 encoding. Supplementary characters are encoded as two code units, the first code unit from the high surrogate range (U+D800 to U+DBFF) and the second code unit from the low surrogate range (U+DC00 to U+DFFF). To include a backslash in the string itself, prefix it with another backslash (\).

For portability and data protection, Oracle recommends specifying only ASCII characters and Unicode code point values in the UNISTR string argument.

Oracle UNISTR() Syntax

Here is the syntax for the Oracle UNISTR() function:

UNISTR(str)

Parameters

str

Required. It can be a text literal or an expression that resolves to character data.

Return Value

The Oracle UNISTR() function returns the given character data in the national character set.

If any of the arguments are NULL, UNISTR() will return NULL.

Oracle UNISTR() Examples

Here are some examples that demonstrate the usage of the Oracle UNISTR() function.

Basic Usage

The following example passes ASCII characters and Unicode code point values to the UNISTR function, which returns the string in the national character set:

SELECT UNISTR('abc\00e5\00f1\00f6')
FROM dual;

输出:

UNISTR('ABC\00E5\00F1\00F6')
_______________________________
abcåñö

NULL Parameter

If any of the arguments are NULL, UNISTR() will return NULL.

SET NULL 'NULL';
SELECT
    UNISTR(NULL)
FROM dual;

输出:

UNISTR(NULL)
_______________
NULL

In this example, we use the SET NULL 'NULL'; statement to display NULL values as the string 'NULL'.

Conclusion

Oracle UNISTR() is a built-in function that returns the given character data in the national character set.