Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between varchar and varchar2 in SQL

Tags:

sql

What is the Difference between varchar and varchar2 in SQL. Please explain in detail with some good example.

like image 626
subanki Avatar asked Oct 14 '10 17:10

subanki


People also ask

What is difference between CHAR VARCHAR and VARCHAR2?

Varchar can store upto 2000 bytes and varchar2 can store upto 4000 bytes. Varchar will occupy space for NULL values and Varchar2 will not occupy any space.

Which one is better VARCHAR or VARCHAR2?

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 .

What does VARCHAR2 mean in SQL?

The VARCHAR2 data type specifies a variable-length character string in the database character set. You specify the database character set when you create your database. When you create a table with a VARCHAR2 column, you must specify the column length as size optionally followed by a length qualifier.

What is VARCHAR2 in SQL example?

Introduction to Oracle VARCHAR2 data type To store variable-length character strings, you use the Oracle VARCHAR2 data type. A VARCHAR2 column can store a value that ranges from 1 to 4000 bytes. It means that for a single-byte character set, you can store up to 4000 characters in a VARCHAR2 column.


2 Answers

Varchar2 is specific to Oracle.

The most significant nonstandard behavior of varchar2 is that an empty string ('') is the same as null.

In standard SQL, null is not the same as any string literal, not even the empty string.

like image 185
Bill Karwin Avatar answered Sep 23 '22 19:09

Bill Karwin


they behave the same, though varchar2 is recommended:

Currently VARCHAR behaves exactly the same as VARCHAR2. However, this type should not be used as it is reserved for future usage.

Source

like image 30
GSto Avatar answered Sep 22 '22 19:09

GSto