How to reduce the size of tif files before inserting into the oracle database

25 views Asked by At

There are hundreds of tif files that have high volume and I want to reduce their size before inserting to database. How can I do? I tried the following function but file but The file disappeared after inserting and has no size

DECLARE
  vImageData BLOB;
  vSizedImage BLOB;
BEGIN
  SELECT file_blob
  INTO vImageData
  FROM adoption_pix
  WHERE ID = 529;
  DBMS_Lob.createTemporary(vSizedImage, FALSE, DBMS_LOB.CALL);
  ORDSYS.OrdImage.processCopy(vImageData, 'maxScale=75 75', vSizedImage);

  UPDATE ADOPTION_PIX SET FILE_BLOB = vSizedImage
  where id = 529;
EXCEPTION WHEN OTHERS THEN
  dbms_output.put_line('Error Msg '|| SQLERRM);
  commit;
END;
1

There are 1 answers

0
Connor McDonald On

If this is a one-off task, easiest way would be to do it as OS leve.

1 Extract blobs to OS

declare
  l_blob      blob;
  l_len       int;
  l_os_file   utl_os_file.file_type;
  l_raw       raw(32767);
  l_size      int := 32767;
  l_idx       int;
begin
  for i in ( select MY_BLOB, MY_FILENAME from MY_TABLE ) 
  loop
    l_idx  := 1;
    l_blob := i.my_blob;
    l_len := dbms_lob.getlength(l_blob);
    l_os_file := utl_os_file.fopen('DIR',i.MY_FILENAME ,'wb', 32767);

    while l_idx <= l_len loop
        dbms_lob.read(l_blob, l_size, l_idx, l_raw);
        utl_os_file.put_raw(l_os_file, l_raw, true);
        l_idx := l_idx + l_size;
    end loop;
  
    utl_os_file.fclose(l_os_file);
  end loop;  
end;
/

2 Use something like 'ffmpeg' to resize them in batch

3 Load them back in

insert into MY_NEW_TABLE 
values ( to_blob(bfilename('DIR','each_file_name'));