0

Is there any way using generic sql to insert a string longer than 4000 chars into a CLOB

New Column Added:

ALTER TABLE MESSAGES ADD (MESSAGE_CLOB CLOB);

INSERT INTO TF_STP_MESSAGES
           (ID,
            MESSAGE_CLOB)
    VALUES (MSG_SEQ.NEXTVAL,
            TO_CLOB ('STRING WITH 10000 CHARACHTER'));

Oracle returns the following message:

PL/SQL: ORA-01704: string literal too long

I have to insert it by SQL

Please advise.

Pravitha V
  • 3,308
  • 4
  • 33
  • 51
Rami Nassar
  • 303
  • 1
  • 4
  • 13
  • See if you can find the answer here: https://community.oracle.com/thread/1068414 .Surprisingly seems to be the exact same question . – sagi Aug 27 '17 at 10:33

1 Answers1

0

You need to use an anonymous block (or a procedure) to run the insert statement by declaring as a CLOB variable and using it in insert.

DECLARE

v_message_clob CLOB := 'STRING WITH 10000 CHARACTERS';

BEGIN 
INSERT INTO TF_STP_MESSAGES
           (ID,
            MESSAGE_CLOB)
    VALUES (MSG_SEQ.NEXTVAL,
            v_message_clob);
END;
/
Kaushik Nayak
  • 30,772
  • 5
  • 32
  • 45