ORA-01403:未找到数据ORA-06512:在“SYS.DBMS_LOB”,第972行ORA-06512:第54行

时间:2016-03-30 05:41:10

标签: oracle oracle10g oracle-apex

我做了一个匿名程序从BLOB字段下载图像(IMAGE),但是我收到一个错误,这是在第57行触发的:DBMS_LOB.READ(lob_loc => v_lob_loc,amount => v_amount,offset => v_offset,buffer => v_buffer);

 DECLARE
    cursor c is 
    select id,REG_CODE  from STUDENT where DBMS_LOB.GETLENGTH(IMAGE)>0;
          v_lob_loc      BLOB;
        v_buffer       RAW(32767);
        v_buffer_size  BINARY_INTEGER;
        v_amount       BINARY_INTEGER;
        v_offset       NUMBER(38) := 1;
        v_chunksize    INTEGER;
        v_out_file     UTL_FILE.FILE_TYPE;


BEGIN

for i in c
loop

 SELECT  IMAGE
INTO    v_lob_loc
FROM   STUDENT
WHERE   id =i.id;

-- +-------------------------------------------------------------+
-- | FIND OUT THE CHUNKSIZE FOR THIS LOB COLUMN                  |
-- +-------------------------------------------------------------+
v_chunksize := DBMS_LOB.GETCHUNKSIZE(v_lob_loc);

IF (v_chunksize < 32767) THEN
    v_buffer_size := v_chunksize;
ELSE
    v_buffer_size := 32767;
END IF;

v_amount := v_buffer_size;


DBMS_LOB.OPEN(v_lob_loc, DBMS_LOB.LOB_READONLY);

-- +-------------------------------------------------------------+
-- | WRITE CONTENTS OF THE LOB TO A FILE                         |
-- +-------------------------------------------------------------+
v_out_file := UTL_FILE.FOPEN(
    location      => 'ALL_IMG_DIR', 
    filename      => I.REG_CODE||'.JPG', 
    open_mode     => 'wb',
    max_linesize  => 32767);

WHILE v_amount >= v_buffer_size
LOOP

 DBMS_LOB.READ(           lob_loc    => v_lob_loc,           amount     => v_amount,          offset     => v_offset,          buffer     => v_buffer);

  v_offset := v_offset + v_amount;

  UTL_FILE.PUT_RAW (
      file      => v_out_file,
      buffer    => v_buffer,
      autoflush => true);

  UTL_FILE.FFLUSH(file => v_out_file);


END LOOP;

UTL_FILE.FFLUSH(file => v_out_file);

UTL_FILE.FCLOSE(v_out_file);

-- +-------------------------------------------------------------+
-- | CLOSING THE LOB IS MANDATORY IF YOU HAVE OPENED IT          |
-- +-------------------------------------------------------------+
DBMS_LOB.CLOSE(v_lob_loc);

UPDATE STUDENT SET IMAGE =EMPTY_BLOB() WHERE ID=I.ID;

end loop;


END;

1 个答案:

答案 0 :(得分:1)

这个oracle文档的链接解释了如何处理这种异常 - https://docs.oracle.com/cd/B10501_01/appdev.920/a96612/d_lob.htm 您可以在标题下找到“特定于BFILE的规则和限制 “,他们解释这个异常来自于到达文件的末尾,以及如何在异常处理程序中包装你的循环以捕获此错误并优雅地处理它。