8

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

subanki
  • 1,411
  • 10
  • 25
  • 48
  • 1
    Possible duplicate of [What is the difference between varchar and varchar2?](http://stackoverflow.com/questions/1171196/what-is-the-difference-between-varchar-and-varchar2) – brandizzi Dec 06 '16 at 11:55

3 Answers3

13

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.

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
  • 1
    +1 Probably worth mentioning that in Oracle, a condition testing whether `Field = ''` always evaluates as NULL (ie. never true), even if `Field` is '' (ie. NULL). –  Oct 15 '10 at 11:40
  • @Mark: Thanks, that's a good point. Whereas in standard SQL, `Field = ''` can be true. – Bill Karwin Oct 15 '10 at 17:09
2

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

GSto
  • 41,512
  • 37
  • 133
  • 184
0

Leigh Riffel on the DBA StackExchange gives the most detailed and precise overview I have read on the difference between VARCHAR and VARCHAR2: https://dba.stackexchange.com/a/1303

Community
  • 1
  • 1
Cale Sweeney
  • 1,014
  • 1
  • 15
  • 37