ORA - 06502:PL / SQL:数字或值错误:批量绑定:截断绑定

时间:2014-03-11 13:31:56

标签: sql oracle plsql oracle11g

这是我的存储过程:

CREATE OR REPLACE PACKAGE BS_SAMPLES AS
  TYPE type_memo_raw IS TABLE OF LONG RAW;
  PROCEDURE MIGRATE_MEMO_TO_MEMO_CLOB(RMEMO OUT  type_memo_raw);
END BS_SAMPLES;

CREATE OR REPLACE PACKAGE BODY BS_SAMPLES AS
  PROCEDURE MIGRATE_MEMO_TO_MEMO_CLOB (RMEMO OUT  type_memo_raw)
  AS
  ls_memo_raw      type_memo_raw;
  BEGIN

   SELECT MR.MEMO_DATA BULK COLLECT
        INTO  ls_memo_raw
        FROM V3_TO_V4_MEMO A, MEMO_RTF MR
       WHERE A.MEMO_ID = MR.MEMO_ID;     

      RMEMO :=ls_memo_raw;
   End MIGRATE_MEMO_TO_MEMO_CLOB;
END BS_SAMPLES;

当我尝试执行过程时,我收到以下错误:

ORA - 06502:PL/SQL : Numeric or Value Error:Bulk Bind : truncated Bind

使用Oracle版本:Oracle Database 11g 11.2.0.2.0版 - 64位生产

表Memo_rtf


Name             Null          Type
MEMO_ID          NOT NULL      NUMBER(10)
MEMO_DATA                      LONG RAW()

表V3_TO_V4_MEMO


Name             Null         Type    
MEMO_ID                       NUMBER(10) 

1 个答案:

答案 0 :(得分:4)

PL / SQL中的LONG ROW和SQL之间存在差异。

在SQL中:

http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements001.htm

“可变长度最大2千兆字节的原始二进制数据。”

在PL / SQL中:

http://docs.oracle.com/cd/B19306_01/appdev.102/b14261/datatypes.htm#i10924

” 您使用LONG RAW数据类型来存储二进制数据或字节字符串。 LONG RAW数据类似于LONG数据,但PL / SQL不解释LONG RAW数据。 LONG RAW值的最大大小为 32760 字节。 “

见下面的例子:

SQL> desc t
 Имя                                       Пусто?   Тип
 ----------------------------------------- -------- ----------------------------
 X                                                  LONG RAW

CREATE OR REPLACE PACKAGE BS_SAMPLES AS
  TYPE type_memo_raw IS TABLE OF LONG RAW;
  PROCEDURE MIGRATE_MEMO_TO_MEMO_CLOB(RMEMO OUT  type_memo_raw);
END BS_SAMPLES;

CREATE OR REPLACE PACKAGE BODY BS_SAMPLES AS
  PROCEDURE MIGRATE_MEMO_TO_MEMO_CLOB (RMEMO OUT  type_memo_raw)
  AS
  ls_memo_raw      type_memo_raw;
  BEGIN

        SELECT t.x BULK COLLECT
        INTO ls_memo_raw 
        FROM t;     

        RMEMO := ls_memo_raw;
   End MIGRATE_MEMO_TO_MEMO_CLOB;
END BS_SAMPLES;

好的,现在我在T表中添加了1行,并将图像(使用PL / SQL Developer工具)放入X列,大小约为90K。

SQL> declare
  2   a BS_SAMPLES.type_memo_raw;
  3  begin
  4     BS_SAMPLES.MIGRATE_MEMO_TO_MEMO_CLOB(a);
  5  end;
  6  /
declare
*
error in line 1:
ORA-06502: PL/SQL: : Bulk Bind: Truncated Bind 
ORA-06512: at  "SCOTT.BS_SAMPLES", line 7 
ORA-06512: at  line 4 


SQL> alter table t modify (x blob);

SQL> select dbms_lob.getlength(x) a from t;

                             a
------------------------------                                                  
                         90025 

好的,我们现在重新创建表格T并添加大小约29K的图像 - 一切都会起作用:

SQL> declare
  2   a BS_SAMPLES.type_memo_raw;
  3  begin
  4     BS_SAMPLES.MIGRATE_MEMO_TO_MEMO_CLOB(a);
  5  end;
  6  /

PL/SQL procedure completed.

SQL> alter table t modify (x blob);

SQL> select dbms_lob.getlength(x) a from t;

                             a                                                  
------------------------------                                                  
                         25554 

所以LONG ROW应该转换为BLOB,这是处理它的最佳方式。