U of A University of Arkansas Division of Agriculture

Pictures of chickens, flowers, wheat, a boy looking through a magnifying glass, irrigation pipe, soybean pods, and fruits and vegetables.

Cooperative Extension Service

Cooperative Extension Service

Agricultural Experiment Station

Steve Rea's
Oracle Tips, Tricks, and Scripts

Link to Steve Rea's Oracle Certification graphic


Search | Publications | Jobs | Personnel Directory | Links

Huge Strings Using LOB's

The VARCHAR2 type in PL/SQL is limited to 32K in length.  What do you do if you need to work with strings longer than 32K?  One way to do this is using Oracle's Large Objects (LOB's), and, in particular, using the DBMS_LOB package to create a Temporary CLOB (Character Large Object) and concatenate your text into that CLOB to build it up.  Note that regular string concatenation (||) just works on strings and results up to 32K in length in PL/SQL, so, when you are concatenating into a LOB, you will have to use the WRITEAPPEND procedure in the DBMS_LOB package (or other similar procedure in that package) to get around that 32K limit.  If you have a CLOB variable called "l_clob", and you do something like "l_clob := l_clob || l_some_string_to_concatenate;", it will convert the l_clob value on the right side of the equation to a VARCHAR2 before doing the concatenation, possibly giving you invalid results or an error.

Below shows how to create a Temporary CLOB and concatenate strings to it resulting in a string longer than 32K (the result is a 96000 byte string).  You can do a Describe on DBMS_LOB (desc dbms_lob) in sqlplus to see what other functions are available to you to work with LOB's.

set serveroutput on
declare
   l_clob clob := empty_clob;
   l_str varchar2 (32000);
begin
   dbms_lob.createTemporary( l_clob, true );
   dbms_lob.open ( l_clob, dbms_lob.lob_readwrite );
   l_str := rpad('*',32000,'*');
   dbms_lob.writeappend ( l_clob, length (l_str), l_str );
   dbms_lob.writeappend ( l_clob, length (l_str), l_str );
   dbms_lob.writeappend ( l_clob, length (l_str), l_str );
   dbms_output.put_line(dbms_lob.getlength(l_clob));
   dbms_lob.close (l_clob);
   dbms_lob.freeTemporary ( l_clob );
end;
/

This Page was Last Updated on 06/04/07

You Are Visitor Number

Hit Counter

Link to CES Home PageBack To CES Home Page

Link to Steve Rea's Oracle PageBack To Steve Rea's Oracle Page

Back to top of this pageBack To Top


© 2006
University of Arkansas
Division of Agriculture
All rights reserved.
Last Date Modified 02/09/2008
Webmaster

University of Arkansas • Division of Agriculture
Cooperative Extension Service
2301 South University Avenue
Little Rock, Arkansas 72204 • USA
Phone (501) 671-2000 • Fax (501) 671-2209
 

MissionDisclaimerEEO
PrivacyFOI