Is there any difference between varchar2 in oracle sql and pl/sql or both are same or there are some implementation difference.
1 Answer
There is at least one difference: the length.
in Pl/sql, it can have a maximum length of 32,767 bytes, while in sql it can only be 4,000 bytes long.
3 Comments
Frank Schmitt
This is true for Oracle versions up to 11gR2. Starting with 12c, maximum length of Varchar2 in SQL is also 32767 bytes, see docs.oracle.com/cd/E16655_01/server.121/e17906/chapter1.htm
ErikL
Thanks Frank, didn't know that yet. Guess I should brush up my Oracle skills a bit.
Jon Heller
Another difference is memory allocation: "For a CHAR variable, or for a VARCHAR2 variable whose maximum size is less than 2,000 bytes, PL/SQL allocates enough memory for the maximum size at compile time. For a VARCHAR2 whose maximum size is 2,000 bytes or more, PL/SQL allocates enough memory to store the actual value at run time. In this way, PL/SQL optimizes smaller VARCHAR2 variables for performance and larger ones for efficient memory use." Although this probably only matters if you're misusing PL/SQL.