Ask the Expert

Technical considerations for using NUMBER vs. VARCHAR2

My question is a continuation of the NUMBER/VARCHAR2 question. You have given functional considerations in your answer, which are quite right. Are there any technical considerations, things like speed of data manipulation or space considerations?

    Requires Free Membership to View

The VARCHAR2 datatype will require the number bytes equivalent to the number of characters. If you store five characters, then five bytes are required to store that data, assuming that your characterset is not a multibyte characterset. If you are using a mutlibyte characterset, then it will require 10 bytes. If you store seven characters, then seven bytes (or 14 in a multibyte) are required to store the data.

The NUMBER datatype will use a varying number of bytes as well. There is one byte used to store the exponent and one to 20 bytes to store the mantissa of the number. So depending on the number you store, you can use between two to 21 bytes of data.

The above gives you the information you need to decide how much storage space is required to store your number in the NUMBER and VARCHAR2 datatypes. Typically, the NUMBER datatype will require less bytes than the VARCHAR2 datatype unless the value is very small, i.e., one, two, three, etc. In the case where the value is one digit, the VARCHAR2 datatype will require one less byte than the NUMBER datatype. However, in today's systems, the storage requirements are typically not a determining factor here.

In most every case, the performance differences are negligable. The smallest unit of I/O is one database block. Unless you are using a very small block size, you still have to read that one block to read the value no matter which datatype you use, provided the block is not already in the cache. So the performance time spent reading the value is the same. If you are going to perform operations on the value and have to convert the value from one datatype to another, then you will incur CPU cycles for the conversion. For instance, you store the value in a VARCHAR2 and then want to perform arithmetic; that value must be converted to a NUMBER datatype first, either explicitly or implicitly.

However, with today's systems, the CPU cycles required are minimal so as to hardly be noticed. I suppose someone could come up with a scenario where the datatype conversions could make a difference, but I would say that such a case would be very rare in practice.

To me, the biggest influencing factors were outlined in my previous response. I really do not see storage requirements or performance to be the defining criteria, except in the most extreme cases.

This was first published in August 2005

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: