Name
charset_recode — Translate a string to another character set
Synopsis
any
charset_recode
(
|
in src_string varchar/nvarchar , |
in src_charset varchar , | |
in
dst_charset
varchar
) ; |
Description
This function translates a string from a given source charset to a destination charset. It provides a generic way of recoding string entities.
The
src_charset
may be a narrow or a wide
string
. If it's a
narrow string
(
VARCHAR
) then the
src_charset
is taken into account and defines the current encoding of the
src_string
. In any other case
src_charset
is ignored.
src_charset
and
dst_charset
are names of system-defined 8 bit charset tables. Use
charsets_list
to obtain a list of currently defined character sets and aliases. If either of these is null, then the charset in effect is used. There are two special character set names - "UTF-8" and "_WIDE_" - that are recognized by this function. These represent UTF-8 encoding of characters and
wide string
(
NVARCHAR
).
Parameters
src_string
The input data to be converted. String or wide string.
src_charset
Input data character set, string .
dst_charset
The charset to convert to, string .
Examples
Example 24.38. Recoding a narrow ISO-8859-1 string as UTF-8
select cast (charset_recode ('\xA9', 'ISO-8859-1', 'UTF-8') as varbinary) -- converts "Copyright sign" to UTF-8 (output 0xC2A9) select cast (charset_recode ('\xC0', 'WINDOWS-1251', 'ISO-8859-5') as varbinary) -- converts "Cyrillic A" from WINDOWS-1251 charset to ISO-8859-5 (output 0xB0). select cast (charset_recode (N'\x410', '_WIDE_', 'WINDOWS-1251') as varbinary) -- converts "Cyrillic A" from Unicode to WINDOWS-1251 charset (result '\xC0'). select charset_recode (N'\x410', '_WIDE_', 'ISO-8859-1') -- converts "Cyrillic A" from Unicode to ISO-8859-1 charset (Not available : result '?').