Oracle TO_NCLOB() Function

Oracle TO_NCLOB() is a built-in function that converts a CLOB value in a LOB column or other character string to an NCLOB value.

Oracle TO_NCLOB() Syntax

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

TO_NCLOB(lob_column | char)

Parameters

lob_column | char

Required. The data to be converted. char can be any data type including CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB.

Return Value

The Oracle TO_NCLOB() function converts a CLOB value in a LOB column or other character string to an NCLOB value.

Oracle Database achieves this by converting the character set of char from the database character set to the national character set.

If any parameter is NULL, TO_NCLOB() returns NULL.

Oracle TO_NCLOB() Examples

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

Basic Usage

The following example uses the TO_NCLOB function to insert some character data into an NCLOB column in the pm.print_media table:

INSERT INTO print_media (product_id, ad_id, ad_fltextn)
   VALUES (3502, 31001,
      TO_NCLOB('Placeholder for new product description'));

NULL Parameters

If any parameter is NULL, TO_NCLOB() returns NULL.

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

输出:

TO_NCLOB(NULL)
_________________
NULL

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

Conclusion

Oracle TO_NCLOB() is a built-in function that converts a CLOB value in a LOB column or other character string to an NCLOB value.