17 Temmuz 2014 Perşembe

What is the difference between varchar2 and char?

We have  same datatype which is string but can be defined with different names.
These two names are defined whilst writing in pl-sql codes in format just like i showed down here;

varchar2(size)
char(size)

They might contain same string value for instance my name 'HAMDI' but why their definitions are different.

Let's have a look this issue with an example.
Let's imagine i declared them as they are below;

my_name varchar2(30);

my_name char(30);


i assigned them 'HAMDI'

string value 'HAMDI' has 5 characters. H-A-M-D-I

when char with my_name definition hold this data,it creates 30 character space in storage even it has 5 characters in it and it keeps rest 25 characters space still empty on storage.
In short,it tells storage that whatever i have as a value inside me, give me an area or space for 30 characters.


when varchar2 with my_name definition hold this data,it just request until 30 character space but takes a space for 5 characters in storage.
Shortly, I have a limit until 30 characters but i have 5 characters now so i am taking a space for 5 characters now.



if you are seeking for performance,char is better than varchar2

for example,if you want to update and make longer the size of content data,it will easily use fixed-space  for character specified under char but if you do the same operation with varchar2,it will try to find a space in storage.











Hiç yorum yok:

Yorum Gönder