Re: How many bytes to store a NUMBER?
Date: 1995/09/20
Message-ID: <tssmithDF7Hyx.JCn_at_netcom.com>#1/1
glc_at_neonramp.com writes:
>I keep getting different answers to this question. The Concepts book
>gives a formula which is something like precision/2+1. Oracle support
>says it is variable depending on the data, based on the formula from
>the book. I have also been told that all numbers take 22 bytes. I have
>done extensive testing myself and the results seem to be somewhere
>between the formula and 22. Does anybody know exactly how many bytes
>it takes to store a number?
The OCI manual and the precompiler guide both describe the storage format for NUMBERs. There are examples also. From these, you should be able to determine exactly the number of bytes required to store any number.
You can also write an OCI program, or a Pro*C program using datatype equivalencing or dynamic SQL, to get the internal representation of a NUMBER. Or, even easier, use dump() in SQL*Plus. But this latter won't give you all the bytes.
Precision/2 + 1 is a pretty good approximation, but not completely accurate. (Actually, it's 1 + floor(prec/2) + 1 + (n < 0 ? 1 : 0) in the Concepts book, which is almost accurate.)
--Tim (tssmith_at_us.oracle.com) Received on Wed Sep 20 1995 - 00:00:00 CEST