diff --git a/CN/modules/ROOT/pages/master/oracle_compatibility/compat_utl_raw.adoc b/CN/modules/ROOT/pages/master/oracle_compatibility/compat_utl_raw.adoc index 7498086d..9a1d64cf 100644 --- a/CN/modules/ROOT/pages/master/oracle_compatibility/compat_utl_raw.adoc +++ b/CN/modules/ROOT/pages/master/oracle_compatibility/compat_utl_raw.adoc @@ -56,6 +56,18 @@ SELECT UTL_RAW.CAST_TO_RAW('ABC') AS raw_value, 默认十六进制显示格式下,`raw_value` 为 `\x414243`。`hex_value` 为 `414243`,是 xref:master/oracle_builtin_functions/rawtohex.adoc[RAWTOHEX] 返回的十六进制文本。 +=== 区分文本字节与十六进制输入 + +`CAST_TO_RAW` 返回输入文本的字节,不会将十六进制数字串解码。输入已经用十六进制表示字节时,应使用 `HEXTORAW`。 + +[source,sql] +---- +SELECT RAWTOHEX(UTL_RAW.CAST_TO_RAW('41')) AS text_bytes, + RAWTOHEX(HEXTORAW('41')) AS decoded_bytes; +---- + +结果分别为 `3431` 和 `41`:文本包含两个 ASCII 字节,而十六进制输入表示一个字节。 + === 转换多字节文本 [source,sql] diff --git a/EN/modules/ROOT/pages/master/oracle_compatibility/compat_utl_raw.adoc b/EN/modules/ROOT/pages/master/oracle_compatibility/compat_utl_raw.adoc index f7a0715b..1c2feb1d 100644 --- a/EN/modules/ROOT/pages/master/oracle_compatibility/compat_utl_raw.adoc +++ b/EN/modules/ROOT/pages/master/oracle_compatibility/compat_utl_raw.adoc @@ -55,6 +55,18 @@ SELECT UTL_RAW.CAST_TO_RAW('ABC') AS raw_value, With the default hexadecimal display format, `raw_value` appears as `\x414243`. The xref:master/oracle_builtin_functions/rawtohex.adoc[RAWTOHEX] function returns the hexadecimal text `414243` in `hex_value`. +=== Distinguish Text Bytes from Hexadecimal Input + +`CAST_TO_RAW` returns the bytes of the input text. It does not decode a string of hexadecimal digits. Use `HEXTORAW` when the input already represents bytes in hexadecimal. + +[source,sql] +---- +SELECT RAWTOHEX(UTL_RAW.CAST_TO_RAW('41')) AS text_bytes, + RAWTOHEX(HEXTORAW('41')) AS decoded_bytes; +---- + +The results are `3431` and `41`: the text contains two ASCII bytes, while the hexadecimal input represents one byte. + === Convert Multibyte Text [source,sql]