Oracle CLOB can't insert beyond 4000 character?

前端 未结 3 1947
北海茫月
北海茫月 2020-12-30 07:02

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\')
<         


        
相关标签:
3条回答
  • 2020-12-30 07:42
    • 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 ')
      );
    
    0 讨论(0)
  • 2020-12-30 07:55

    The maximum for one time insertion is 4000 characters (the maximum string literal in Oracle). However you can use the lob function dbms_lob.append() to append chunks of (maximum) 4000 characters to the clob:

    CREATE TABLE don (x clob);
    
    
    DECLARE 
     l_clob clob;
    BEGIN
      FOR i IN 1..10
      LOOP
        INSERT INTO don (x) VALUES (empty_clob()) --Insert an "empty clob" (not insert null)
        RETURNING x INTO l_clob;
    
        -- Now we can append content to clob (create a 400,000 bytes clob)
        FOR i IN 1..100
        LOOP
          dbms_lob.append(l_clob, rpad ('*',4000,'*'));
          --dbms_lob.append(l_clob, 'string chunk to be inserted (maximum 4000 characters at a time)');
        END LOOP;
      END LOOP;
    END;
    
    0 讨论(0)
  • 2020-12-30 07:56

    Use a clob column and use sqlldr to import the data from a csv.

    sqldeveloper can generate the necessary control .ctl script for you.

    0 讨论(0)
提交回复
热议问题