Home » SQL & PL/SQL » SQL & PL/SQL » PLS-00172: string literal too long while passing large XML as input to a procedure (Oracle Database 21c Express Edition Release 21.0.0.0.0 - Production Version 21.3.0.0.0)
PLS-00172: string literal too long while passing large XML as input to a procedure [message #690039] Mon, 23 September 2024 09:59 Go to next message
gopieee16
Messages: 28
Registered: May 2011
Location: Chennai
Junior Member

Hi Experts,

We have a scenario, where our front end team will send a XML with size greater than 40000 characters we need to pass this xml as input to a procedure and do the desired logic which is reading the nodes and inserting into a table. When i pass huge xml as input im getting "PLS-00172: string literal too long" error. I know there is a PLSQL limit of 32767, but wanted to know is there any work around or alternate way we can handle this?

I have given a sample code here to read and display data

CREATE OR REPLACE PROCEDURE process_large_xml1(
  p_xml_data  IN  CLOB,          
  p_out_value OUT VARCHAR2       
) AS
BEGIN

  BEGIN
    FOR rec IN (
      SELECT name_value, description_value
      FROM XMLTABLE('/root/items/item'
                     PASSING XMLTYPE(p_xml_data)
                     COLUMNS 
                       name_value VARCHAR2(100) PATH 'name',
                       description_value VARCHAR2(200) PATH 'description')
    ) LOOP
      DBMS_OUTPUT.PUT_LINE('Item Name: ' || rec.name_value);
      DBMS_OUTPUT.PUT_LINE('Item Description: ' || rec.description_value);

    END LOOP;
    
    p_out_value := 'XML data processed successfully';
  
  EXCEPTION
    WHEN NO_DATA_FOUND THEN
      p_out_value := 'No data found in XML for the specified path';
      DBMS_OUTPUT.PUT_LINE('No data found in XML');
    WHEN OTHERS THEN
      p_out_value := 'Error occurred';
      DBMS_OUTPUT.PUT_LINE('Error while processing XML: ' || SQLERRM);
  END;
END process_large_xml1;
/
I have attached the sample XML and anonymous block im calling this procedure for reference.

Please give your sugesstions




Re: PLS-00172: string literal too long while passing large XML as input to a procedure [message #690040 is a reply to message #690039] Mon, 23 September 2024 10:10 Go to previous messageGo to next message
Michel Cadot
Messages: 68716
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

1/ If you want where the comes from from, first remove WHEN OTHERS clause. Read WHEN OTHERS.
2/ From what you posted, the error comes from the PL/SQL you attached and not the procedure:
SQL> DECLARE
  2    l_output_value VARCHAR2(100);
  3  l_xml_data clob := '
  4
  5  <root>
  6      <items>
  7          <item>
  8              <name>Item 1</name>
  9              <description>This is a detailed d
...
344          </item>
345          <!-- Repeat as needed to reach 5000 characters -->
346      </items>
347  </root>
348  ';
349
350  BEGIN
351
352    process_large_xml1(l_xml_data, l_output_value);
353
354    DBMS_OUTPUT.PUT_LINE (l_output_value);
355
356  END;
357  /
l_xml_data clob := '
                   *
ERROR at line 3:
ORA-06550: line 3, column 20:
PLS-00172: string literal too long
Split the string into several substrings like 'xxx'||'yyy'||'zzz'...

[Updated on: Mon, 23 September 2024 10:11]

Report message to a moderator

Re: PLS-00172: string literal too long while passing large XML as input to a procedure [message #690041 is a reply to message #690039] Mon, 23 September 2024 10:13 Go to previous messageGo to next message
cookiemonster
Messages: 13958
Registered: September 2008
Location: Rainy Manchester
Senior Member
clobs will happily take longer values than 4,000 characters (not 40,000), that's why they exist.
String literals - any hardcoded value in quotes - won't.
So your error is due to the amount of data inside those quotes.
You get around the issue by breaking the string literal down into chunks that are 4000 characters or less and then concatenating them into the clob variable:
DECLARE

  l_output_value VARCHAR2(100);
  l_xml_data clob;

BEGIN

  l_xml_data := to_clob('<first 4000 characters>');
  l_xml_data := l_xml_data || '<next 4000 characters>');

<repeat until you have everything>

  process_large_xml1(l_xml_data, l_output_value);
  
  DBMS_OUTPUT.PUT_LINE (l_output_value);

END;
/
That'll make your anonymous block work.
It probably won't help with any issue with the front end code.
Re: PLS-00172: string literal too long while passing large XML as input to a procedure [message #690042 is a reply to message #690041] Mon, 23 September 2024 10:27 Go to previous messageGo to next message
gopieee16
Messages: 28
Registered: May 2011
Location: Chennai
Junior Member

Thanks Michel sure i will lok into it,

Thanks Cookiemonster

Got clarified,

thanks for your time and effort for replying
Re: PLS-00172: string literal too long while passing large XML as input to a procedure [message #690059 is a reply to message #690039] Sat, 28 September 2024 14:15 Go to previous messageGo to next message
lucianalopes
Messages: 1
Registered: August 2024
Junior Member
Did you resolve This problem?
Did you do?
I am passing This for the same problem.
Could posto the solution here, please?
Thanks you
Re: PLS-00172: string literal too long while passing large XML as input to a procedure [message #690060 is a reply to message #690059] Sat, 28 September 2024 15:03 Go to previous message
Michel Cadot
Messages: 68716
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

The solution has been given: split the constant string.

Previous Topic: How avoid More than one Join With Same table (merged)
Next Topic: SQL Macro using UTL_FILE
Goto Forum:
  


Current Time: Sat Nov 23 02:00:05 CST 2024