blobデータの読み込み

1568 ワード

select * from d_41_001 t;

create or replace procedure get_blob
(
 t_ywlsh varchar2,out_blob out varchar2
)
as
  load_blob blob;
  amount int;
  offset int:=1;
  buffer varchar2(3000);
begin
     select tabd4101_sqs into load_blob from d_41_001 where ywlsh=t_ywlsh;
     amount:=dbms_lob.getlength(load_blob);
     dbms_lob.read(load_blob,amount,offset,buffer);
     out_blob:=utl_raw.cast_to_varchar2(buffer);
end;

declare 
        out_string varchar2(3000);
begin
     get_blob('WH-A4120101201027041',out_string);     
end;


 create or replace  procedure get_blob (t_ywlsh varchar2,poname varchar2) IS
   l_file      UTL_FILE.FILE_TYPE;
   l_buffer    RAW(32767);
   l_amount    BINARY_INTEGER := 32767;
   l_pos       INTEGER := 1;
   l_blob      BLOB;
   l_blob_len  INTEGER;
 BEGIN
    select tabd4101_sqs into l_blob from d_41_001 where ywlsh=t_ywlsh;
 
     l_blob_len := DBMS_LOB.GETLENGTH(l_blob);
     l_file := UTL_FILE.FOPEN('BLOBDIR',poname,'wb', 32767);
 
     WHILE l_pos < l_blob_len LOOP
       DBMS_LOB.READ (l_blob, l_amount, l_pos, l_buffer);
       dbms_output.put_line(l_buffer);
       UTL_FILE
       UTL_FILE.PUT_RAW(l_file, l_buffer, TRUE);
       l_pos := l_pos + l_amount;
     END LOOP;
     
     UTL_FILE.FCLOSE(l_file);
   
   END;