6.2 Explicit Data Type Conversion Functions
This section describes the explicit conversion functions in SQL and PL/SQL to convert other data types to and from CLOB, NCLOB, and BLOB data types.
-
TO_CLOB(): Converts fromVARCHAR2,NVARCHAR2, orNCLOBto aCLOB -
TO_NCLOB(): Converts fromVARCHAR2,NVARCHAR2, orCLOBto anNCLOB -
TO_BLOB(varchar|clob, destcsid,[mime_type]): Converts the object from its current character set to the given character set indestcsid. The resultant object isBLOB. Following are various ways in which you can use the conversion function:TO_BLOB(character, destcsid)TO_BLOB(character, destcsid, mime_type)TO_BLOB(clob, destcsid)TO_BLOB(clob, destcsid, mime_type)
If the
destcsidis 0, then it converts to the database character set ID. The parametermime_typeis applicable only toINSERTandUPDATEstatements on Secure FileLOBcolumns. If themime_typeparameter is used inSELECTstatements or in temporary or BasicFileLOBs, then it is ignored. TO_BLOB(varchar): Converts the input toRAWbefore converting toBLOB. In other words,TO_BLOB(HEXTORAW(varchar))andTO_BLOB(varchar)are equivalent.Note:
TO_BLOB(CLOB)is not supported.-
TO_CHAR(): Converts aCLOBto aCHARtype. When you use this function to convert a character LOB into the database character set, if the LOB value to be converted is larger than the target type, then the database returns an error. Implicit conversions also raise an error if the LOB data does not fit. -
TO_NCHAR(): Converts anNCLOBto anNCHARtype. When you use this function to convert a character LOB into the national character set, if the LOB value to be converted is larger than the target type, then the database returns an error. Implicit conversions also raise an error if the LOB data does not fit. -
CASTdoes not directly support any of the LOB data types. When you useCASTto convert aCLOBvalue into a character data type, anNCLOBvalue into a national character data type, or aBLOBvalue into aRAWdata type, the database implicitly converts the LOB value to character or raw data and then explicitly casts the resulting value into the target data type. If the resulting value is larger than the target type, then the database returns an error.
Parent topic: PL/SQL Semantics for LOBs