2

I am getting this error 'ORA-01704: string literal too long' while I am trying to insert data from SQL table in Oracle table. In my Oracle table I have a column with XMLTYPE column type. When I was creating table I specified XML column like this:

  CREATE TABLE REPORTS (
       ...
    XML XMLTYPE NULL ); 

Apart from this column, before it I have others 23 columns and when I exclude from insert statement XML column, insert is passing. XML column contain a data in XML format of all others 23 columns from table. Whether I should add some additional specification in my XML column for length or something other?

3
  • What error do you get? Please add that to the question. Commented Jul 1, 2016 at 14:12
  • What version of Oracle are you using, and how large is the XML in the particular INSERT? Commented Jul 1, 2016 at 14:14
  • I am using this version 'Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production' and XML size is 4,39 KB (4.497 bytes) Commented Jul 1, 2016 at 14:27

2 Answers 2

6

My guess is you are passing the XML as a literal to the insert statement. Oracle's SQL can only handle up to 4000 characters in a literal. Otherwise you need to use bind variables and pass it in chunks. Or you can use PL/SQL.

For example, this should work without issue because the literal

<MyMessage>Meeesaaagee</MyMessage> 

is only 34 characters:

CREATE TABLE TEST_REPORTS
(
   ID            NUMBER,
   DESCRIPTION   VARCHAR2 (50),
   XML           XMLTYPE NULL
);

INSERT INTO TEST_REPORTS (ID, DESCRIPTION, XML)
     VALUES (1, 'BLAH BLAH', XMLTYPE.CREATEXML ('<MyMessage>Meeesaaagee</MyMessage>'));

COMMIT;

But if you had: Meeesaaagee (+ 3976 extra characters)

You will get the ORA-01704: string literal too long error.

You could try:

DECLARE
    in_xml_value varchar2(32767);
BEGIN
    in_xml_value := '<MyMessage>MeeesaaageeBLAHBLAHBLAH<--repeat--></MyMessage>';
    INSERT INTO TEST_REPORTS (ID, DESCRIPTION, XML)
     VALUES (1, 'BLAH BLAH', XMLTYPE.CREATEXML (in_xml_value);
    commit;
END;
/

Do do it w/o PL/SQL code and to use bind variables, well you would have to talk with an application developer. It is outside of Oracle (and outside of my knowledge).

Sign up to request clarification or add additional context in comments.

2 Comments

Nick S, sorry for the late reply. This with PL/SQL is the only solution. My question is how can I pass the parameters to this PL/SQL procedure and XML parameter assign to this declare parameter in_xml_value varchar2(32767)? PL/SQL not my strong side. Thank you for your answer.
Nick S, after a while of testing I succeeded to resolve my problem with your method using PL/SQL. Thank you a lot!
0

Where is the error? Show the insert statement. I do not see any problem here:

CREATE TABLE TEST_REPORTS
(
   ID            NUMBER,
   DESCRIPTION   VARCHAR2 (50),
   XML           XMLTYPE NULL
);

INSERT INTO TEST_REPORTS (ID, DESCRIPTION, XML)
     VALUES (1, 'BLAH BLAH', XMLTYPE.CREATEXML ('<MyMessage>Meeesaaagee</MyMessage>'));

1 Comment

Everything is ok with the statement. I know because I used it with the other table but XML document of that table is smaller than this one and that xml is inserting into table perfectly. I think that the problem is with the size of XML document.

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.