ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

What is the difference between varchar and varchar2?

user-image
تم إضافة السؤال من قبل Mohammad odeh , Software Engineer , bayt.com
تاريخ النشر: 2013/05/11
Mohammad Abrar Abrar
من قبل Mohammad Abrar Abrar , Team Leader , Enkindle Technologies Pvt Ltd

[i].
VARCHAR(5) is fixed length, right padded with null VARCHAR2(5) is variable length.
[ii].
VARCHAR and VARCHAR2 both are of variable character.
VARCHAR can have Maximum 2000 character while VARCHAR2 can contain maximum 4000 character.
[iii].
VARCHAR is of ANSI SQL standard while VARCHAR2 is of Oracle standard.

Faraz Khan
من قبل Faraz Khan , ecommerce manager , Saudi Ceramics Company

It would seem that Oracle at one time had plans to give a different definition to VARCHAR than to VARCHAR2.
It has told customers this and recommends against using VARCHAR.
Whatever their plans were, as of 11.2.0.2 VARCHAR is identical to VARCHAR2.
Here is what the SQL Language Reference 11g Release 2 says: Do not use the VARCHAR data type.
Use the VARCHAR2 data type instead.
Although the VARCHAR data type is currently synonymous with VARCHAR2, the VARCHAR data type is scheduled to be redefined as a separate data type used for variable-length character strings compared with different comparison semantics.
The PL/SQL User's Guide and Reference 10g Release 2 puts it this way: Currently, VARCHAR is synonymous with VARCHAR2.
However, in future releases of PL/SQL, to accommodate emerging SQL standards, VARCHAR might become a separate datatype with different comparison semantics.
It is a good idea to use VARCHAR2 rather than VARCHAR.
The Database Concepts 10g Release 2 document says the same thing in stronger terms: The VARCHAR datatype is synonymous with the VARCHAR2 datatype.
To avoid possible changes in behavior, always use the VARCHAR2 datatype to store variable-length character strings.
The Oracle 9.2 and 8.1.7 documentation say essentially the same thing, so even though Oracle continually discourages the use of VARCHAR, so far they haven't done anything to change it's parity with VARCHAR2.

مستخدم محذوف‎
من قبل مستخدم محذوف‎

1.
VARCHAR: § Stores strings of variable length.
§ The length parameter specifies the maximum length of the strings § It stores up to 2000 bytes of characters § It will occupy space for NULL values § The total length for strings is defined when database was created.
2.
VARCHAR(2): § Stores strings of variable length.
§ The length parameter specifies the maximum length of the strings § It stores up to 4000 bytes of characters § It will not occupy space for NULL values

Veeraiah Yadav
من قبل Veeraiah Yadav , SAP BI - Sr. Consultant , Samsung SDSE

Hi, The difference between Varchar and Varchar2 is both are variable length but only2000 bytes of character of data can be store in varchar where as4000 bytes of character of data can be store in varchar2.
varchar means fixed length character data(size) ie., min size-1 and max-2000 where as varchar2 means variable length character data ie., min-1 to max-4000 -Thanks

SRINIVAS KATLA
من قبل SRINIVAS KATLA , trainee , CDAC

1.
VARCHAR is going to be replaced by VARCHAR2 in next version.
So, Oracle suggests the use VARCHAR2 instead of VARCHAR while declaring datatype.
2.
VARCHAR can store up to 2000 bytes of characters while VARCHAR2 can store up to 4000 bytes of characters.
3.
If we declare datatype as VARCHAR then it will occupy space for NULL values, In case of VARCHAR2 datatype it will not occupy any space.

Shamsudheen kootteeri
من قبل Shamsudheen kootteeri , PHP Developer , Arion Infotech

VARCHAR vs.
VARCHAR2 _____________________1.
VARCHAR is going to be replaced by VARCHAR2 in next version.
So, Oracle suggests the use VARCHAR2 instead of VARCHAR while declaring datatype.2.
VARCHAR can store up to2000 bytes of characters while VARCHAR2 can store up to4000 bytes of characters.3.
If we declare datatype as VARCHAR then it will occupy space for NULL values, In case of VARCHAR2 datatype it will not occupy any space.

Mohamed Mansour
من قبل Mohamed Mansour , Java Developer , Arrow Electronics

We can make the question more general, and make a comparison between character string values storage: char, varchar and varchar21.
The length of CHAR is fixed, and the the VARCHAR2 length of changes, for example, store the string "abc", CHAR (20), your stored characters will account for20 bytes (including17 blank characters)same VARCHAR2 (20)only occupy three bytes in length,20 just max, When your characters stored is less than20, the actual length of storage.2.
The CHAR efficiency is slightly higher than VARCHAR2 efficiency.3.
Currently VARCHAR VARCHAR2 synonyms.
VARCHAR type of industrial standards can be stored in an empty string, but oracle does not do so, although it retained the right to do so later.
Oracle developed a data type VARCHAR2, this is not a standard type VARCHAR, it will varchar columns in the database characteristics can be stored empty string instead stored NULL value.
If you want to have backward compatibility, Oracle recommends the use VARCHAR2 rather than VARCHAR.
When CHAR, when to use varchar2? CHAR and VARCHAR2 is a contradictory unity, both complementary relationship.
VARCHAR2 save space than CHAR CHAR will be slightly worse efficiency than some, in order to obtain efficient must sacrifice a certain amount of space, which is we often say 'in the database design space for efficiency'.
VARCHAR2 than CHAR save space, but if a VARCHAR2 column often be modified, but is modified each time a different length of the data, which may cause the phenomenon of 'line migration'(Row Migration), which caused the excess I/O is To try to avoid database design and tuning, CHAR instead of VARCHAR2 in this case would be better.
char also automatically filled spaces, automatic replenishment spaces, but spaces do not delete select after you insert into a char field.

bilal khalid
من قبل bilal khalid , Software Engineer , Civil Aviation Authority

1.
VARCHAR is NOT going to be replaced by VARCHAR2 in the next version.
It is reserved for redefinition in some future version, probably well beyond11g, if ever.
This warning has been around since the two types were first introduced in Oracle6 around1989.
It is there to allow Oracle some flexibility should the need arise.2.
The two types are currently synonymous, and so the storage limitations are identical.3.
As for #2, there is no difference between VARCHAR and VARCHAR2 in handling of NULL values because they are currently the same type.
While I'm at it, VARCHAR2 does NOT contain an additional length indicator (as the DUMP output clearly shows), CHAR is NOT faster than VARCHAR2, and VARCHAR does NOT use space any differently to VARCHAR2 and never has done.
There is no good reason to use CHAR for anything, even fixed-length keys, and there never has been.
I've never seen so much complete rubbish on one page in my life.

Zaher Hazeem
من قبل Zaher Hazeem , Senior Software Engineer , N2V - Startappz

** In Oracle there is no VARCHAR, only VARCHAR2 is supported as I remembered.
** The difference is NULL and empty string '' ** For example xx1 is VARCHAR2 column, and try to run WHERE xx1 IS NULL : will return values but, WHERE xx1='' doesn't return any value.
** So empty string equals NULL values, and use NULL instead of empty string

Gufran Izhar Hussain
من قبل Gufran Izhar Hussain , Digital Marketing Manager , valsense

declaring datatype as VARCHAR will occupy space for NULL values, In case of VARCHAR2 datatype it will not occupy any space.

Muhammad Majid Saleem
من قبل Muhammad Majid Saleem , Senior PHP Developer / Project Manager , SwaamTech

VARCHAR is reserved by Oracle to support distinction between NULL and empty string in future, as ANSI standard prescribes.
VARCHAR2 does not distinguish between a NULL and empty string, and never will.
If you rely on empty string and NULL being the same thing, you should use VARCHAR2.
Reference: http://stackoverflow.com/questions/1171196/what-is-the-difference-between-varchar-and-varchar2

المزيد من الأسئلة المماثلة