Home » SQL & PL/SQL » SQL & PL/SQL » Insert from large string into CLOB (Oracle 11)
Insert from large string into CLOB [message #556955] Thu, 07 June 2012 09:50 Go to next message
El_Coto
Messages: 9
Registered: January 2012
Junior Member
Hello people,
I'm looking for a way to insert strings larger than 40.000 characters in a CLOB-field without geting the "ORA-01461: can bind a LONG value only for insert into a LONG column".

Something like this:
insert into MyClobTable(ID,Data) values ('101','A string containing more than 40000 characters...')

The problem is that a Java-application concatinates the string from a MSSQL-DB so I don't store the string in my oracle-DB. As far as I'm aware this means I can't chop my string in pieces and use declare to put the pieces in variables, right?

Below is an example I found but I don't think I can apply it on my case, correct?



SQL> CREATE TABLE myClob
  2  (id NUMBER PRIMARY KEY,
  3   clob_data CLOB);

Table created.

SQL>
SQL> INSERT INTO myClob VALUES (101,null);

1 row created.

SQL>
SQL> declare
  2    clob_pointer CLOB;
  3    v_buf VARCHAR2(1000);
  4    Amount BINARY_INTEGER :=1000;
  5    Position INTEGER :=1;
  6  BEGIN
  7    v_buf :=rpad('A',1000,'A');
  8
  9    insert into myClob values (1 ,EMPTY_CLOB());
 10
 11    commit;
 12
 13    SELECT clob_data INTO clob_pointer FROM myClob WHERE id = 1 FOR UPDATE;
 14    DBMS_LOB.OPEN (clob_pointer,DBMS_LOB.LOB_READWRITE);
 15
 16    FOR i IN 1..500 LOOP
 17
 18      DBMS_LOB.WRITE (clob_pointer,Amount,Position,v_buf);
 19
 20      Position :=Position +Amount;
 21
 22    END LOOP;
 23
 24    DBMS_LOB.CLOSE (clob_pointer);
 25
 26  END;
 27  /

PL/SQL procedure successfully completed.

SQL>
SQL> drop table myClob;

Table dropped.

SQL>



Thanks for looking into this!

[Updated on: Thu, 07 June 2012 09:56]

Report message to a moderator

Re: Insert from large string into CLOB [message #556956 is a reply to message #556955] Thu, 07 June 2012 10:27 Go to previous messageGo to next message
Michel Cadot
Messages: 68774
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Quote:
Something like this


You cannot do something like this.
You have to use lob functions as you did it in your PL/SQL.
See Database Application Developer's Guide - Large Objects

Regards
Michel
Re: Insert from large string into CLOB [message #557635 is a reply to message #556956] Thu, 14 June 2012 08:02 Go to previous messageGo to next message
El_Coto
Messages: 9
Registered: January 2012
Junior Member
I managed to get this to work by using a insert-concat loop inside my java app..

First the initial insert that creates the record,
insert into Table(Id,Data) values(101,'First 4000 chars')


Then an update for as long as there is still data in my concatinated string,
update Table set Data = Data || 'Next 4000 chars' where DATA like 'First 4000 chars'
Re: Insert from large string into CLOB [message #557636 is a reply to message #557635] Thu, 14 June 2012 08:09 Go to previous message
Michel Cadot
Messages: 68774
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Performances and space killer.

Regards
Michel
Previous Topic: Cant figure out the error
Next Topic: oracle sql and plsql
Goto Forum:
  


Current Time: Sat Jan 31 15:41:36 CST 2026