Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

Free Oracle Tips

HTML Text

 Home
 E-mail Us
 Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

 Applications
 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB   


 

 

 


 

 

 
 

Oracle UTL_COMPRESS Package

Oracle Tips by Burleson Consulting

Advanced Oracle Utilities: The Definitive Reference by Rampant TechPress is written by top Oracle database experts (Bert Scalzo, Donald Burleson, and Steve Callan).  The following is an excerpt from the book.

Introduced in Oracle 10g, the UTL_COMPRESS package can be used to compress and uncompress large objects (raw, blob or bfile). For all practical purposes, think of UTL_COMPRESS as PL/SQL’s means of compressing or zipping files. When looking at the various procedures and functions, many are prefixed with LZ. The algorithm used to perform the compression is based on the Lempel-Ziv algorithm and when used, the code is based on the LZW or Lempel-Ziv-Welch implementation.

 

Oracle’s documentation for this package is sparse in terms of showing a full-scale example. Sparse is not even the correct word here. Nonexistent is a better descriptor. A MOSC note (249974.1) shows two examples and various pages on the Internet can be searched.

 

The actual implementation of this package is pretty easy to use once an example is seen. Many of the examples shown elsewhere include a length comparison among the input, the compressed, and the uncompressed lengths. Ideally, the input and uncompressed lengths should be the same. You may find that the compressed length is longer than the input length. This occurs when the input length is small or short. The overhead of building a dictionary can make the compressed length longer than the input length.

 

In this simple example, create input, compress it, uncompress it and evaluate the lengths of each.

 

SET SERVEROUTPUT ON

DECLARE

l_in_blob            BLOB;

l_compressed_blob    BLOB;

l_uncompressed_blob  BLOB;

BEGIN

-- Set some values

l_in_blob     := TO_BLOB(UTL_RAW.CAST_TO_RAW

('This is a long string of words used for this example'));

l_compressed_blob   := TO_BLOB('0');

l_uncompressed_blob := TO_BLOB('0');

 

-- Compress the string

UTL_COMPRESS.lz_compress

(src => l_in_blob, dst => l_compressed_blob);

 

-- Uncompress the string

UTL_COMPRESS.lz_uncompress

(src => l_compressed_blob, dst => l_uncompressed_blob);

 

-- Compare the results with the input

DBMS_OUTPUT.put_line('Input length is    : ' || LENGTH(l_in_blob));

DBMS_OUTPUT.put_line('Compressed length  : ' || LENGTH(l_compressed_blob));

DBMS_OUTPUT.put_line('Uncompressed length: ' || LENGTH(l_uncompressed_blob));

 

-- Caller responsibility to free up temporary LOBs

-- See Operational Notes in the documentation

DBMS_LOB.FREETEMPORARY(l_in_blob);

DBMS_LOB.FREETEMPORARY(l_compressed_blob);

DBMS_LOB.FREETEMPORARY(l_uncompressed_blob);

END;

/

Input length is    : 52

Compressed length  : 67

Uncompressed length: 52

 

PL/SQL procedure successfully completed.

Note that the compressed length is longer than the input length. Adding a few more characters to the input string yields the following: 

SET SERVEROUTPUT ON

DECLARE

l_in_blob            BLOB;

l_compressed_blob    BLOB;

l_uncompressed_blob  BLOB;

BEGIN

-- Set some values

l_in_blob     := TO_BLOB(UTL_RAW.CAST_TO_RAW

('This is a long string of words used for this example.

Now is the time for all good men to come to the aid of their country'));

l_compressed_blob   := TO_BLOB('0');

l_uncompressed_blob := TO_BLOB('0');

 

-- Compress the string

UTL_COMPRESS.lz_compress

(src => l_in_blob, dst => l_compressed_blob);

 

-- Uncompress the string

UTL_COMPRESS.lz_uncompress

(src => l_compressed_blob, dst => l_uncompressed_blob);

 

-- Compare the results with the input

DBMS_OUTPUT.put_line('Input length is    : ' || LENGTH(l_in_blob));

DBMS_OUTPUT.put_line('Compressed length  : ' || LENGTH(l_compressed_blob));

DBMS_OUTPUT.put_line('Uncompressed length: ' || LENGTH(l_uncompressed_blob));

 

-- Caller responsibility to free up temporary LOBs

-- See Operational Notes in the documentation

DBMS_LOB.FREETEMPORARY(l_in_blob);

DBMS_LOB.FREETEMPORARY(l_compressed_blob);

DBMS_LOB.FREETEMPORARY(l_uncompressed_blob);

END;

/

 

Input length is    : 122

Compressed length  : 113

Uncompressed length: 122

 

PL/SQL procedure successfully completed.

 

That little bit extra for the input string pushed it over the top in terms of having the compression take any real effect.

Note that the LZ_COMPRESS subprogram is overloaded since more than one signature method can be used to invoke it. The quality parameter is set to a default of 6.  This parameter provides a trade-off between speed of compress and quality of compression. It takes quite a few more words or length of input before there is a difference in what the quality input does.

As an example, take the text about quality in the documentation and use that as the input string, and vary the quality from 1 to 9. If this block of text is used as an example, be sure to remove the single quotes around quality near the end.


 

 

  
 

 
 
 
 
Oracle performance tuning software
 
 

 

 
 
 
Oracle performance Tuning 10g reference poster
 
 
 
Oracle training in Linux commands
 
Oracle training Excel
 
Oracle training & performance tuning books
 

 

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  and include the URL for the page.


                    









Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


 

Copyright © 1996 -  2012 

All rights reserved.

Oracle © is the registered trademark of Oracle Corporation.