below code is working fine for compress the large size file as well.
- DECLARE
- in_filename VARCHAR2(100);
- src_file BFILE;
- v_content BLOB;
- v_blob_len INTEGER;
- v_file utl_file.file_type;
- v_buffer RAW(32767);
- v_amount BINARY_INTEGER := 32767;
- v_pos INTEGER := 1;
- BEGIN
- in_filename := 'Test.txt';
- src_file := bfilename('DIR_UTL_COM_TEST', in_filename);
- dbms_lob.fileopen(src_file, dbms_lob.file_readonly);
- v_content := utl_compress.lz_compress(src_file, 9);
- v_blob_len := dbms_lob.getlength(v_content);
- v_file := utl_file.fopen('DIR_UTL_COM_TEST',
- in_filename || '.gz',
- 'wb');
- WHILE v_pos < v_blob_len LOOP
- dbms_lob.READ(v_content, v_amount, v_pos, v_buffer);
- utl_file.put_raw(v_file, v_buffer, TRUE);
- v_pos := v_pos + v_amount;
- END LOOP;
- utl_file.fclose(v_file);
- EXCEPTION
- WHEN OTHERS THEN
- IF utl_file.is_open(v_file) THEN
- utl_file.fclose(v_file);
- END IF;
- RAISE;
- END;
複製代碼
|