4

How I can insert very long text 100000 <length(string) < 300000 oracle clob or blob?

DECLARE
    v_long_text CLOB;
BEGIN
    v_long_text := 'my long string text';

    INSERT INTO MYTABLE_NAME 
    VALUES      (v_long_text);
END;

its metod is not worked, returned error PLS-00172: string literal too long

3
  • What is the datatype of column ? Commented Apr 13, 2018 at 12:27
  • I have both and does not matter which one will work Commented Apr 13, 2018 at 12:30
  • Does this answer your question? Oracle 10: Using HEXTORAW to fill in blob data Commented Jun 2, 2020 at 22:19

3 Answers 3

8

You literal is implicitly a varchar, so you are not able to assign to v_long_text value larger than maximum literal of varchar (maximum varchar length in plsql is 32767).

You can use concatenation:

DBMS_LOB.APPEND(v_long_text, 'very long string');
DBMS_LOB.APPEND(v_long_text, 'yet another long string');

Of course, I am assuming that MYTABLE_NAME column type is a CLOB

UPDATE: Sample code:

DECLARE
    v_long_text CLOB;
BEGIN
   DBMS_LOB.CREATETEMPORARY(v_long_text,true);
   DBMS_LOB.APPEND(v_long_text, dbms_random.string('U', 20000));
   DBMS_LOB.APPEND(v_long_text, dbms_random.string('U', 20000));
   DBMS_LOB.APPEND(v_long_text, dbms_random.string('U', 20000));
   DBMS_LOB.APPEND(v_long_text, dbms_random.string('U', 20000));
   DBMS_LOB.APPEND(v_long_text, dbms_random.string('U', 20000));
   DBMS_LOB.APPEND(v_long_text, dbms_random.string('U', 20000));
   DBMS_LOB.APPEND(v_long_text, dbms_random.string('U', 20000));

    INSERT INTO my_table VALUES (v_long_text);
END;
Sign up to request clarification or add additional context in comments.

2 Comments

How Can I do that ? please write query simple
helped me a lot! this should be the best option
0

Other approaches are good. But, if you have the long string stored somewhere in a file system, you could make use of these things.

  • Load it using SQL* loader : This is easy and straightforward and can be automated to read from file system.
  • Use unix split utility with -b option to split the long text in the file into smaller chunks ( say 32000 or 4000 ) and in a shell script construct multiple insert statements.

something like :

split -b 4000 yourbigfile split_files_
ct=1
for chunk in $(cat split_files_??)
 do
   # first time
   echo "INSERT INTO table_name(col_name) VALUES ('${chunk}');"
   # 2nd and subsequent
  echo " update table_name set col_name = col_name || '$chunk';"
  ct=$((ct + 1))
done >yourinsert_script.sql
  • Create a PL/SQL procedure that reads the text from a file using UTL_FILE and inserts to the table.

3 Comments

Have you checked the solution? In a similar case I've got an ORA-01489: result of string concatenation is too long.
@kunis : I'm not sure how you're doing it. As far as I remember it did work for me. It's possible that somewhere in your code you are concatenating literals who's total size exceeds 4000 chars
@nayak UPDATE "<table>" SET BK_DATASET_SQL = 'SELECT SK_ACCNT_PUR_HIST_ID||''' || chr(38) || '3''|| ..... ' WHERE ... If the text that I'm going to put into BK_DATASET_SQL is too long (more then 4000 symbols), I'm getting ORA-01489: result of string concatenation is too long
0
DECLARE
    definition_clob CLOB;

BEGIN
dbms_lob.createtemporary(definition_clob, true);
dbms_lob.append(definition_clob,'String 1.. ">
dbms_lob.append(definition_clob,'String 2.. ">
.
.
.
INSERT INTO TABLE
(CLOB_COLUMN)
VALUES
(definition_clob)

COMMIT
dbms_lob.freetemporary(definition_clob);

END;
/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.