Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down