Oracle CLOB can't insert beyond 4000 character?

Dolphin picture Dolphin · Aug 23, 2013 · Viewed 31.9k times · Source

How to insert more than 4000 characters to CLOB type column?

--create test table s
create table s
(
      a clob
);
insert into s values('>4000 char')

Results in an error:

ORA-01704:the string too long.

When I want to insert string >4000 for one time, how to do it? Is it be possible?

When I read the Oracle reference, CLOB can save max 4GB(Gigabyte)?

Answer

gunn picture gunn · Mar 14, 2018
  • split the long character string into 4000 character or less chunks
  • create clobs for each chunk using to_clob() function
  • concatenate the clobs

Here is an example:

insert into <table> (clob_column)
  values
  (
      to_clob(' <=4000 symbols ')
    ||to_clob(' <=4000 symbols ')
    ||to_clob(' <=4000 symbols ')
    ...
    ||to_clob(' <=4000 symbols ')
  );