【问题标题】:Using DBMS_LOB.SUBSTR on a BLOB results in ORA-06502在 BLOB 上使用 DBMS_LOB.SUBSTR 会导致 ORA-06502
【发布时间】:2011-12-17 11:08:17
【问题描述】:

当我尝试在 BLOB 字段上运行 dbms_lob.substr 函数时,我收到以下错误:

ORA-06502:PL/SQL:数字或值错误:原始变量长度太长

ORA-06512:在第 1 行

我的查询:

select dbms_lob.substr(my_report, 10000, 1) 
from my_table where my_table.report_id = :myid

根据dbms_lob.substr documentation,我应该可以使用第二个参数中的一个值,最大为32767,并且报告的大小超过200,000字节,因此在范围内。

玩过这个数字,发现可以在substr函数的amount参数(第二个参数)中使用的make值是2000。

有人知道为什么吗?

【问题讨论】:

    标签: oracle oracle11g ora-06502


    【解决方案1】:

    2000 个八位字节的长度限制仅适用于 sql 引擎。在 Pl/sql 中,您可以利用最长为 32767 (2^15-1) 的整个范围。

    从 12c 开始,2000 的长度限制已取消。

    但是,在 12c 之前,sqlplus 客户端存在长度限制,不允许列大小超过 4000(11g2 的值)。

    以下代码适用于 11g2 及更高版本

    var myid number;
    exec :myid := 1234; -- whatever
    
    DECLARE
        l_r   RAW(32767);
    BEGIN
        select dbms_lob.substr ( my_report, 2000, 1 ) head
          into l_r
          from my_table
         where my_table.report_id = :myid  
           ;
    
      l_r := UTL_RAW.COPIES ( l_r, 10 );
      dbms_output.put_line ( 'id ' || :myid || ', len(l_r) = ' || utl_raw.length(l_r));
    END;
    /
    show errors 
    

    ...虽然这个版本需要 12c:

    var myid number;
    exec :myid := 1234; -- whatever
    
    DECLARE
        l_r   RAW(32767);
    BEGIN
        select dbms_lob.substr ( my_report, 32767, 1 ) head
          into l_r
          from my_table
         where my_table.report_id = :myid  
           ;
    
      dbms_output.put_line ( 'id ' || :myid || ', len(l_r) = ' || utl_raw.length(l_r));
    END;
    /
    show errors 
    

    【讨论】:

      【解决方案2】:

      函数将结果作为 RAW 数据类型返回,RAW 数据类型的最大大小为 2000 字节。

      参考资料:

      http://download.oracle.com/docs/cd/B10501_01/server.920/a96540/sql_elements2a.htm#SQLRF0021

      http://dbaforums.org/oracle/index.php?showtopic=8445

      【讨论】:

        猜你喜欢
        • 2020-03-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-08-17
        • 2015-08-28
        • 2013-11-07
        相关资源
        最近更新 更多