tags:

views:

417

answers:

3

difference between varchar and varchar2?

+7  A: 

As for now, they are synonyms.

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.

Quassnoi
Hadn't heard that rationale before, that's useful. Thanks.For the record, it is still totally ridiculous that the main character type in Oracle is "varchar2". Doesn't that strike anybody else as a terrible kludge? Seems like how I would have solved some problem in my first week of learning to program.
Ian Varley
@Ian: main type is `VARCHAR2` because currently there is no type that behaves like `VARCHAR` should. In fact, you should not use `VARCHAR` at all until it's implemented properly.
Quassnoi
Thanks, @Quassnoi. So I guess the stupid part is that Oracle doesn't have a proper VARCHAR like every other database, then? There's something stupid going on here, I'm sure of it ... :)
Ian Varley
@Ian: when Oracle was being developed, there were no standards. By the time the standards emerged it already had a burden of legacy apps. We all know how it happens.
Quassnoi
Yeah, I've been there. :)
Ian Varley
A: 

For now, they are exactly the same. It's a pre-reserved variable that may be used later in the future.

Jovan
VARCHAR being the pre-reserved variable, correct?So it is best to use VARCHAR2.
marked
+11  A: 

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

Taken from: Difference Between CHAR, VARCHAR, VARCHAR2

Brian