Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: Using CLOB
<span style='font-size:
10.0pt;font-family:Arial;color:navy'>Funny, I just did this today for a developer,
it does not go to a table, it uses Oracle 8i's new feature to use clob's
without a table to point to, thus memory only.
<span style='font-size:
10.0pt;font-family:Arial;color:navy'>
<span
style='font-size:10.0pt;font-family:"Courier New";color:black;font-weight:bold'>create<font
size=2 color=black face="Courier New"><span style='font-size:10.0pt;font-family:
"Courier New";color:black'> or <span
style='font-weight:bold'>replace procedure
DisplayClob
is
myclob1 <span style='font-weight:
bold'>CLOB;
myclob2 <span style='font-weight:
bold'>CLOB;
buffer <span style='font-weight:
bold'>VARCHAR2(<font size=2 color="#0000f0"
face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New";
color:#0000F0'>32000<span
style='font-size:10.0pt;font-family:"Courier New";color:black'>);
output <span style='font-weight:
bold'>VARCHAR2(<font size=2 color="#0000f0"
face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New";
color:#0000F0'>32000<span
style='font-size:10.0pt;font-family:"Courier New";color:black'>);
amount <span style='font-weight:
bold'>NUMBER := <font size=2 color="#0000f0"
face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New";
color:#0000F0'>50<span
style='font-size:10.0pt;font-family:"Courier New";color:black'>;
offset <span style='font-weight:
bold'>NUMBER := <font size=2 color="#0000f0"
face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New";
color:#0000F0'>1<span
style='font-size:10.0pt;font-family:"Courier New";color:black'>;
clob_length <span style='font-weight:
bold'>NUMBER;
read_counter NUMBER;
begin
<span
style='font-size:10.0pt;font-family:"Courier New";color:red;font-style:italic'>--
Create text for the buffer<font size=2 color=black
face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New";
color:black'>
buffer := <span
style='font-size:10.0pt;font-family:"Courier New";color:#0000F0'>'1234567890abcdefghijklmnopqrstuvwxyz'<font
size=2 color=black face="Courier New"><span style='font-size:10.0pt;font-family:
"Courier New";color:black'>;
DBMS_OUTPUT.PUT_LINE(<font size=2 color="#0000f0"
face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New";
color:#0000F0'>'Buffer: '<font size=2 color=black
face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New";
color:black'> || buffer);
<span
style='font-size:10.0pt;font-family:"Courier New";color:red;font-style:italic'>--
Determine the length of the buffer<font size=2 color=black
face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New";
color:black'>
amount := length(buffer);
DBMS_OUTPUT.PUT_LINE(<font size=2 color="#0000f0"
face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New"; color:#0000F0'>'Buffer Length: '<font size=2 color=black face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New";color:black'> || TO_CHAR(amount));
<span
style='font-size:10.0pt;font-family:"Courier New";color:red;font-style:italic'>--
Create lob locator (Temporary)<font size=2 color=black
face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New";
color:black'>
DBMS_LOB.CREATETEMPORARY(myclob1,FALSE,DBMS_LOB.<span
style='font-weight:bold'>CALL);
DBMS_LOB.CREATETEMPORARY(myclob2,FALSE,DBMS_LOB.<span
style='font-weight:bold'>CALL);
<span
style='font-size:10.0pt;font-family:"Courier New";color:red;font-style:italic'>--
Write data into the clob initially.<font size=2 color=black
face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New";
color:black'>
DBMS_LOB.WRITE(myclob2, amount, <font
size=2 color="#0000f0" face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New";color:#0000F0'>1<font size=2
color=black face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New";
color:black'>, buffer);
FOR i <span style='font-weight:
bold'>IN <font size=2 color="#0000f0"
face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New";
color:#0000F0'>1<span
style='font-size:10.0pt;font-family:"Courier New";color:black'> .. <font
size=2 color="#0000f0" face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New";color:#0000F0'>1000<font size=2
color=black face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New";
color:black'>
<font size=2
color=black face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New";
color:black'>LOOP<font size=2
color=black face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New";
color:black'>
<span
style='mso-spacerun:yes'> DBMS_LOB.APPEND(myclob1, myclob2);
END <span
style='font-weight:bold'><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>LOOP<font
size=2 color=black face="Courier New"><span style='font-size:10.0pt;font-family:
"Courier New";color:black'>;
<span
style='font-size:10.0pt;font-family:"Courier New";color:red;font-style:italic'>--
Display size of clob<font size=2 color=black
face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New";
color:black'>
clob_length := DBMS_LOB.GETLENGTH(myclob1);
DBMS_OUTPUT.PUT_LINE(<font size=2 color="#0000f0"
face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New";
color:#0000F0'>'CLOB Size: '<font size=2 color=black
face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New";
color:black'> || clob_length);
<span
style='font-size:10.0pt;font-family:"Courier New";color:red;font-style:italic'>--
Display data from the temporary clob<font size=2 color=black
face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New";
color:black'>
read_counter := <span
style='font-size:10.0pt;font-family:"Courier New";color:#0000F0'>0<font
size=2 color=black face="Courier New"><span style='font-size:10.0pt;font-family:
"Courier New";color:black'>;
WHILE read_counter < clob_length
<font size=2
color=black face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New";
color:black'>LOOP<font size=2
color=black face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New";
color:black'>
DBMS_LOB.<span style='font-weight:
bold'>READ(myclob1, amount, offset, output);
DBMS_OUTPUT.PUT_LINE(<font
size=2 color="#0000f0" face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New";color:#0000F0'>'Clob contents: '<font
size=2 color=black face="Courier New"><span style='font-size:10.0pt;font-family:
"Courier New";color:black'> || output);
read_counter := read_counter +
amount;
END <span
style='font-weight:bold'><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>LOOP<font
size=2 color=black face="Courier New"><span style='font-size:10.0pt;font-family:
"Courier New";color:black'>;
DBMS_LOB.FREETEMPORARY(myclob1);
DBMS_LOB.FREETEMPORARY(myclob2);
end DisplayClob;
<span style='font-size:
10.0pt;font-family:Arial;color:navy'>
<span style='font-size:
10.0pt;font-family:Arial;color:navy'>
<span style='font-size:12.0pt;
color:navy;mso-no-proof:yes'>"Do not criticize someone until you walked a
mile in their shoes, that way when you criticize them, you are a mile a way and
have their shoes."
<span style='font-size:18.0pt;
font-family:"Comic Sans MS";color:navy;mso-no-proof:yes'>Christopher R. Spence<font
color=navy>
<span
style='font-size:10.0pt;font-family:"Comic Sans MS";color:navy;mso-no-proof:
yes'>Oracle DBA<span style='color:navy;
mso-no-proof:yes'>
<span
style='font-size:10.0pt;font-family:"Comic Sans MS";color:navy;mso-no-proof:
yes'>Phone: (978) 322-5744<span
style='color:navy;mso-no-proof:yes'>
<span
style='font-size:10.0pt;font-family:"Comic Sans MS";color:navy;mso-no-proof:
yes'>Fax: (707) 885-2275<span
style='color:navy;mso-no-proof:yes'>
<span style='font-size:10.0pt;
font-family:"Comic Sans MS";color:navy;mso-no-proof:yes'>Fuelspot<font
color=navy>
<span
style='font-size:10.0pt;font-family:"Comic Sans MS";color:navy;mso-no-proof:
yes'>73 Princeton Street<span style='color:navy;
mso-no-proof:yes'>
<span
style='font-size:10.0pt;font-family:"Comic Sans MS";color:navy;mso-no-proof:
yes'>North, Chelmsford 01863<span
style='color:navy;mso-no-proof:yes'>
<span
style='font-size:10.0pt;font-family:Tahoma'>-----Original Message-----
From: Yuval Arnon
[mailto:Yuval.Arnon_at_wwfent.com]
Sent: Monday, September 17, 2001
2:40 PM
To: Multiple recipients of list <font
size=2 face=Tahoma>ORACLE-L<font
size=2 face=Tahoma>
Subject: Using CLOB
<span
style='font-size:12.0pt'>
<span style='font-size:
10.0pt;font-family:Arial'>Hi,
How
can you assign a text to a CLOB column defined in the DECLARE section of
PL/SQL.I am getting an error on wrong type.
<span style='font-size:
10.0pt;font-family:Arial'>i.e..
<span style='font-size:
10.0pt;font-family:Arial'>SQL> l
1 declare
2 c clob ;
3 BEGIN
4 c := 'This is a test';
5* END;
SQL>
/
c :=
'This is a test';
*
ERROR
at line 4:
ORA-06550:
line 4, column 6:
PLS-00382:
expression is of wrong type
ORA-06550:
line 4, column 1:
PL/SQL:
Statement ignored
<span
style='font-size:10.0pt;color:blue;font-style:italic'>Yuval Arnon
Received on Mon Sep 17 2001 - 14:24:58 CDT