0

我需要从数据库中检索几个大的波形文件,并且想检索分成更小的波形文件(大约 5Mb)。我能怎么做?我看过程序 dbms_lob.read,但它返回的最大文件大小为 32Kb。

问候

procedure extract_blob(p_id in number, wrote_length in out number, chunk out blob) is
   len_file binary_integer;
   myblob blob;
   myname varchar2(255);
   buffer_length number := 32760;

   begin    
     select file_wav_data, file_wav_name, dbms_lob.getlength(file_wav_data)
     into myblob, myname, lun_file 
     from t_wav 
     where id = p_id;

     if(len_file > wrote_length) then
         dbms_lob.read(myblob,buffer_length,wrote_length+1,chunk);
         wrote_length := wrote_length + buffer_length;
     else wrote_length := -999; --EOF
     end if;
   end;
4

1 回答 1

2

您可能想要使用临时 LOB:

procedure extract_blob(
    p_id in number,
    offset in number,
    chunk_length in out number,
    chunk out blob
) is
    chunk blob;
    wav_data blob;
    full_length number;
    chunk_length number;

begin    
    select file_wav_data, dbms_lob.getlength(file_wav_data)
    into wav_data, full_length
    from t_wav 
    where id = p_id;

    chunk_length := greatest(full_length - offset, 0);
    if chunk_length = 0 then
        return;
    end if;

    dbms_lob.createtemporary(chunk, TRUE);

    dbms_lob.copy(chunk, wav_data, chunk_length, 0, offset);

end extract_blob;

如果可能,您应该在处理完临时 LOB 后从客户端释放它(使用DBMS_LOB.FREETEMPORARY)。

于 2012-12-03T09:33:16.000 回答