UTL_COMPRESS package lets you compress and decompress binary data (RAW, BLOB, and BFILE).
SQL>
SQL> SET SERVEROUTPUT ON
SQL> DECLARE
2 l_original_blob BLOB;
3 l_compressed_blob BLOB;
4 l_uncompressed_blob BLOB;
5 BEGIN
6 l_original_blob :=
7 TO_BLOB(UTL_RAW.CAST_TO_RAW('1234567890123456789012
8 345678901234567890'));
9 l_compressed_blob := TO_BLOB('1');
10
11 l_uncompressed_blob := TO_BLOB('1');
12 UTL_COMPRESS.lz_compress (src => l_original_blob,
13 dst => l_compressed_blob);
14 UTL_COMPRESS.lz_uncompress (src => l_compressed_blob,
15 dst => l_uncompressed_blob);
16 DBMS_OUTPUT.put_line('Original Length : ' ||
17 LENGTH(l_original_blob));
18 DBMS_OUTPUT.put_line('Compressed Length : ' ||
19 LENGTH(l_compressed_blob));
20 DBMS_OUTPUT.put_line('Uncompressed Length: ' ||
21 LENGTH(l_uncompressed_blob));
22 DBMS_LOB.FREETEMPORARY(l_original_blob);
23 DBMS_LOB.FREETEMPORARY(l_compressed_blob);
24 DBMS_LOB.FREETEMPORARY(l_uncompressed_blob);
25 END;
26 /
Original Length : 46
Compressed Length : 38
Uncompressed Length: 46
PL/SQL procedure successfully completed.
Related examples in the same category