What is the Difference between varchar and varchar2 in SQL. Please explain in detail with some good example.
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.
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 .
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With