While working with some large scripts I encountered errors related with the 4000 character limit that VARCHAR2 has in SQL but not in PL/SQL.
As explained here the VARCHAR2 datatype has a 4000 character limited, while the PL/SQL has a much larger limit of 32,767.
Why does that difference exist? Wouldn't have been better to have both VARCHAR2 with the same limit? It seems a rather confusing and prone to error decision.
Update
I updated my question to add ansible's comment. Oracle VARCHAR2 and PL/SQL VARCHAR2 limit are on bytes, not in characters. This can have significant impact in multibyte characters system.
Best Answer
It is just a fact of life. Different history, different beliefs, different goals.
Your might find this post on PL/SQL and its goals helpful in seeing some of the differences: http://docs.oracle.com/cd/B10501_01/appdev.920/a96624/03_types.htm
It amusingly starts with:
There are ANSI Standard data types, but I believe that
VARCHAR2
is an Oracle standard, not a part of ANSI. It appears from history that Oracle'sVARCHAR2
was designed to overcome the limitations of their earlierVARCHAR
implementation.Having said that, practically every SQL dialect has some unique datatype that is not accepted by all other SQL dialects. (I primarily work with MS SQL Server, but do at times need to absorb data from other systems.)
Fortunately there are a number of online resources to help you in mapping one datatype to another as you move between the products of multiple vendors. Usually it is not too difficult. Note: it is not only strings (such as
CHAR,VARCHAR
) that can have conflicting definitions.