Oracle PL/SQL:将字符串分配给原始变量时出现 ORA-06502 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13471988/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Oracle PL/SQL: ORA-06502 error when assigning a string to a raw variable
提问by user685428
I try to load some textinformation into clob fields. I reduced the code I'm having trouble to the following snippet:
我尝试将一些文本信息加载到 clob 字段中。我将遇到问题的代码简化为以下代码段:
DECLARE
WS_MAIN_CHUNK RAW(12001);
BEGIN
WS_MAIN_CHUNK := 'Do';
END;
/
It gives me the error ORA-06512 PL/SQL: numeric or value error: hex to raw conversion error. Why is the string 'Do' a hex value and how can I fix it -> Just assign the string to the raw variable?
它给了我错误ORA-06512 PL/SQL: numeric or value error: hex to raw conversion error。为什么字符串“Do”是十六进制值,我该如何修复它 -> 只需将字符串分配给原始变量?
Thx for your help
谢谢你的帮助
回答by Nick Krasnov
In Oracle, RAW
data type is used to store binary data and any data that is byte oriented. You cannot directly assign a string value to a variable of RAW
datatype. If there is such a need, you can use utl_raw
package and cast_to_raw
function to do that:
在 Oracle 中,RAW
数据类型用于存储二进制数据和任何面向字节的数据。您不能直接将字符串值分配给RAW
数据类型的变量。如果有这样的需要,你可以使用utl_raw
包和cast_to_raw
函数来做到这一点:
SQL> DECLARE
2 WS_MAIN_CHUNK raw(12001);
3 BEGIN
4 WS_MAIN_CHUNK := utl_raw.cast_to_raw('Do');
5 END;
6 /
PL/SQL procedure successfully completed