Skip to Main Content
  • Questions
  • VARCHAR2(32767) accepts no more than 4000 chars

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, David.

Asked: August 03, 2006 - 11:51 am UTC

Last updated: August 03, 2006 - 5:47 pm UTC

Version: 9.0.2

Viewed 10K+ times! This question is

You Asked

Tom:
I have oracle 9i rls 2.

I am experiencing a size problem using varchar2.
(4000 limit?) .

I have ( as shown below) a type with field that
I expect to be able to hold 32k of text.


CREATE OR REPLACE TYPE PO_Comment_Detail AS OBJECT (
PO VARCHAR2(14),
Head_or_Line VARCHAR2(14),
buyer_code varchar2(6),
POComment VARCHAR2(32767)
)

I have a procedure that works flawlessly except for
populating POComments. It accumilates a good deal of
into a varchar2(32767) and trys to put it into POComment.
To get data into POComments I have to reduce its size
substr(AComment2Write,1,4000) works and
substr(AComment2Write,1,4001) doesn't.

Any thoughts on what is happening or more to the point
how I can make it work ?

Thanks
Dave




and Tom said...

in plsql, a varchar2 maybe up to 32k.

in SQL - a varchar2 is limited to 4000 bytes.

so, while you can have a plsql variable of 32k, you cannot use a varchar2 in the database to "persist" (store it)


ops$tkyte%ORA9IR2> create or replace type myType as object ( x varchar2(32767) );
2 /

Type created.

ops$tkyte%ORA9IR2> desc myType;
Name Null? Type
---------------------------------------- -------- ----------------------------
X VARCHAR2(32767)

ops$tkyte%ORA9IR2> create table t of mytype;
create table t of mytype
*
ERROR at line 1:
ORA-00910: specified length too long for its datatype


ops$tkyte%ORA9IR2> create table t ( x mytype );
create table t ( x mytype )
*
ERROR at line 1:
ORA-00910: specified length too long for its datatype


ops$tkyte%ORA9IR2> declare
2 l_x mytype;
3 begin
4 l_x := mytype( rpad( '*', 32767, '*' ) );
5 dbms_output.put_line( length( l_x.x ) );
6 end;
7 /
32767

PL/SQL procedure successfully completed.


to persist something larger than 4000 bytes, you will be using the CLOB type.

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

A reader, August 04, 2006 - 11:53 pm UTC

amazing how natuarally you can bring up examples to validate the point.

Keep up the great work!!

More to Explore

CLOB/BLOB/etc

Complete documentation on Securefiles and Large Objects here