dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Tip: Understanding UNCOMPRESSED_LENGTH in MySQL

Learn how to get the compressed text results to be the exact length of the original text.


advertisement

In MySQL, once we use the COMPRESS method to compress a particular text, the LENGTH of the resultant text is not the same as that of the original text.

However, using UNCOMPRESSED_LENGTH method on the compressed text results in the exact length of the original text, even though the text is currently compressed.

Example:

SELECT UNCOMPRESSED_LENGTH(COMPRESS('MyName'))

+-----------------------------------------+
| UNCOMPRESSED_LENGTH(COMPRESS('MyName')) |
+-----------------------------------------+
|                                      6  | 
+-----------------------------------------+

Now, use the below query

SELECT LENGTH(COMPRESS('MyName'))

+----------------------------+
| LENGTH(COMPRESS('MyName')) |
+----------------------------+
|                         18 | 
+----------------------------+

This indicates the different values in length using the two different LENGTH methods.

 

Visit the DevX Tip Bank

 



   
Sridhar M S. is a Java developer from Bangalore, India. He holds a master's degree in Computer Science.
Thanks for your registration, follow us on our social networks to keep up-to-date