Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance difference between VARCHAR2 to NUMBER

If I query my DataBase (Oracle) with unique Index on multiple columns, Will there be any performance difference if I change one of the columns from VARCHAR2 to NUMBER?
If there is, is it significant?

(It's varchar2 because I need '0' at the beginning but I can change it in the presentation layer in my app)

like image 234
gdoron is supporting Monica Avatar asked Nov 26 '11 19:11

gdoron is supporting Monica


People also ask

Why CHAR is faster than VARCHAR2?

Searching is faster in CHAR as all the strings are stored at a specified position from the each other, the system doesnot have to search for the end of string. Whereas in VARCHAR the system has to first find the end of string and then go for searching.

Can we store number in VARCHAR2 in Oracle?

You can insert any VARCHAR2(n) value into a LONG database column because the maximum width of a LONG column is 2147483648 bytes or two gigabytes. However, you cannot retrieve a value longer than 32767 bytes from a LONG column into a VARCHAR2(n) variable.

Which is better VARCHAR2 or nvarchar2?

So if you have “Normal” character set in most of the rows then varchar2 is better than nvarchar2 if your database character set is UTF%, since varchar2 will use 1 byte for every normal character and nvarchar2 will use 2 bytes for every normal character.


1 Answers

More knowledgeable people than me tell me that in Oracle the performance difference between number and varchar2 depends entirely on your data, since internally they have very similar representations. See the following:

https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:2669498700346402356

but also look at the "Internal Numeric Format" section of:

http://docs.oracle.com/cd/B28359_01/server.111/b28318/datatype.htm#CNCPT012

If, for example, your varchar data was actually single characters (such as 'Y', 'N') then you'd probably be better off with varchars than numerics. If you've got fewer than 100 codes but your string equivalents were 8 characters long then you'd probably be better off with numerics than varchars.

like image 174
Huw Roberts Avatar answered Sep 27 '22 20:09

Huw Roberts