In this tutorial you will learn about difference between varchar and varchar2.
Varchar stands for variable length character string. Both Varchar and Varchar2 are data types to store character strings for particular column (field) in databases. These are reserved by ORACLE. If we relay empty string and NULL being the same, then we should use varchar2 instead of varchar. Because it treats both null and empty strings as same. Oracle stated that, “Do not use varchar datatype” although currently both used for same purpose. But in future varchar usage may change. It is for future purpose. So now it is better to stick with varchar2.
Difference between varchar and varchar2
Varchar | Varchar2 |
1) Varchar can identify NULL and empty string separately. | 1) Varchar2 cannot identify both separately. Both considered as same for this. |
2) Varchar can store minimum 1 and maximum 2000 bytes of character data. | 2) Varchar2 can store minimum 1 and maximum 4000 bytes of character data. |
3) Allocate fixed size of data irrespective of the input.
Ex: We defined varchar (15) and entered only 10 characters. But it allocates space for entire 15 characters. |
3) Allocate variable size of data based on input.
Ex: We defined varchar2 (15) and entered only 10 characters. Then varchar2 will allocate space for 10 characters only but not for 15. |
4) For varchar data, extra spaces are padded to the right side. | 4) For varchar2 extra spaces will be truncated. |
5) Varchar is ANSI Sql standard | 5) Varchar2 is Oracle standard |
6) Varchar definition may change in future. | 6) Varchar2 definition will not change. It is standard. |
7) Varchar is an external datatype. | 7) Varchar2 is an internal datatype. |
Comment below if you have doubts regarding varchar vs varchar2.
The post Difference between varchar and varchar2 appeared first on The Crazy Programmer.
from The Crazy Programmer https://www.thecrazyprogrammer.com/2018/01/difference-varchar-varchar2.html
Comments
Post a Comment