1

I have a problem when trying to convert CLOB from a table to BLOB into another table. Basically I'm looping inside a PLSQL array, the first call to DBMS_LOB.convertToBlob always works well, but the next iterations either create an empty blob or give me an error ORA-22275: invalid LOB locator specified, depending on whether I initialize my blob inside or outside the loop.

So, if I do :

BEGIN
FOR i IN 1 .. rs.COUNT
LOOP
DBMS_LOB.createTemporary (v_blob, TRUE);
DBMS_LOB.convertToBlob (v_blob,
rs (i).v_clob,
DBMS_LOB.LOBMAXSIZE,
v_in,
v_out,
DBMS_LOB.DEFAULT_CSID,
v_lang,
v_warning);
[...]
DBMS_LOB.freeTemporary(v_blob);

It converts the first blob well but only returns empty blobs for the other ones.

If I do:

BEGIN
DBMS_LOB.CREATETEMPORARY (v_blob, TRUE);
FOR i IN 1 .. rs.COUNT
LOOP
DBMS_LOB.convertToBlob(...);

It also converts the first blob well but I get the ORA-22275: invalid LOB locator specified error after the first iteration.

How could I avoid this? I can't seem to find good explanation for this. Thanks for your help!

4

5 回答 5

2

一定是NULL价值问题。一定CLOB不是。NULL下面的代码给了我第三轮的错误。

set serveroutput on
declare 
   TYPE rs_rec_type IS RECORD (
      v_clob clob
      );
  TYPE rs_rec_table_type IS TABLE OF rs_rec_type INDEX BY pls_integer;
  rs   rs_rec_table_type;
  v_blob    blob;
  v_in      integer := 1;
  v_out     integer := 1;
  v_lang    integer := 0;
  v_warning integer := 0;
BEGIN
  rs(1).v_clob := 'foo';
  rs(2).v_clob := 'bar';
  rs(3).v_clob := null;
  FOR i IN 1 .. rs.COUNT
  LOOP
      DBMS_LOB.createTemporary (v_blob, TRUE);
      dbms_output.put_line('i='||i);  
      DBMS_LOB.convertToBlob (v_blob,
                             rs (i).v_clob,
                             DBMS_LOB.LOBMAXSIZE,
                             v_in,
                             v_out,
                             DBMS_LOB.DEFAULT_CSID,
                             v_lang,
                             v_warning);
      dbms_output.put_line('done i='||i); 
      DBMS_LOB.freeTemporary(v_blob);     
  end loop;
end;

输出

Error report:
ORA-06502: PL/SQL: numeric or value error: invalid LOB locator specified: ORA-22275
ORA-06512: at "SYS.DBMS_LOB", line 991
ORA-06512: at line 20
06502. 00000 -  "PL/SQL: numeric or value error%s"
*Cause:    
*Action:
i=1
done i=1
i=2
done i=2
i=3
于 2013-05-28T20:21:55.013 回答
0

在循环中使用临时 blob 时,我遇到了类似的问题。我通过每次初始化 in、out、lang 和 warning 参数来解决它。

詹姆士。

于 2013-07-25T11:31:24.473 回答
0

这对我有用:

declare
  cursor note is
    select id, rtf_clob
      from rtf_data
     where rtf_clob is not null
    for update of rtf_blob;
  l_blob        blob;
  l_amt         integer := dbms_lob.lobmaxsize;
  l_dest_offset integer := 1;
  l_src_offset  integer := 1;
  l_csid        integer := dbms_lob.default_csid;
  l_ctx         integer := dbms_lob.default_lang_ctx;
  l_warn        integer;

begin
  for note_rec in note loop
    l_blob        := null;
    l_amt         := dbms_lob.lobmaxsize;
    l_dest_offset := 1;
    l_src_offset  := 1;
    l_csid        := dbms_lob.default_csid;
    l_ctx         := dbms_lob.default_lang_ctx;
    l_warn        := null;
    dbms_lob.createTemporary(l_blob, true);
    dbms_lob.convertToBlob(l_blob,
                           note_rec.rtf_clob,
                           l_amt,
                           l_dest_offset,
                           l_src_offset,
                           l_csid,
                           l_ctx,
                           l_warn );

    update rtf_data
       set rtf_blob = l_blob
     where note_rec.id = id;

    dbms_lob.freeTemporary(l_blob); 
  end loop;
end;
/

没有重新初始化循环内的变量,只有第一条记录创建了一个 blob。

于 2017-04-05T13:52:06.353 回答
0

我有一个类似的问题,我想出了一些关于DBMS_LOB.convertToBlob. 您输入的变量dest_offsetsrc_offset在完成相关过程后更改,因此您必须在每次迭代后重置它们,以防您要创建多个文件

我不知道这是否特别有助于直接解决这个问题,但请记住这一点,以备将来参考,以防DBMS_LOB.convertToBlob在循环中使用。

于 2021-05-06T09:44:55.757 回答
0

当 CLOB 包含 NULL 时,可能会发生此错误。这意味着 CLOB 变量将 NULL 传递给 DBMS_LOB.convertToBlob

于 2020-12-22T18:35:57.463 回答