amar on web

Number sizing fallacy

Why does the number 110 takes 3 bytes of space, while the number 1100 takes only 2 bytes?


      SQL>select vsize(110), vsize(1100) from dual; 

      VSIZE(110) VSIZE(1100) 
      __________ ___________ 
               3           2 


From MetaLink 
 Solution: Oracle stores a number in base 100 format. 
              Each byte can store 2 digits. 
              One byte is reserved for the exponent 
              An additional byte is required for negative numbers. 
            
             You can use the VSIZE command to calculate the number 
             of bytes required to  store a NUMBER. SELECT VSIZE(100) from dual; 

 Solution Explanation:  
   Here are some examples: 
   select vsize(1) from dual;   -- 2 bytes            /* 1 for the digit, 1 for exponent*/ 
   select vsize(-1) from dual;  -- 3 bytes           /* 1 additional for sign */ 
   select vsize(110) from dual; -- 3 bytes          /* 2 for digits + 1 for exponent*/ 
   
  select vsize(1100) from dual; - 2 bytes  
      /* Note that the number is stored as (11*10exp2) Thus it requires 1 byte 
          for the two digits (11) and one byte for the exponent(2) */ 
    
   select vsize(-10.02) from dual; 4 bytes         
               /*One for sign, 2 for digits(1002) and one for exponent(-2)  */ 
    
   For additional reference: Oracle Concepts Guide 

Best viewed in medium text size. Please refresh this page (F5) to view the latest information.
This page was created on 16-dec-2001 and last updated on 16-dec-2001.
please forward all queries to amar_padhi@fastmail.fm