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

665 Views Asked by At

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.

1

There are 1 best solutions below

0
On

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;
/