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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 01:16:14  来源:igfitidea点击:

Oracle PL/SQL: ORA-06502 error when assigning a string to a raw variable

oracleplsql

提问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, RAWdata 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 RAWdatatype. If there is such a need, you can use utl_rawpackage and cast_to_rawfunction 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