Link to home
Start Free TrialLog in
Avatar of jgudavalli
jgudavalli

asked on

Pl/SQL procedure runs successfully but no output generated

Hi All,
I really need help. My problem definition:
1. I have a database table "testcase" in oracle 10g which has a column "testdata" of type clob. "testdata" column has xml data in it. I want to fetch the value of taga <Match> under <Expected_After> tag, concatinate the values if more than one <Match> tag exists and later
insert this value into a column "EXPECTAFTER"  in the same DB table i.e "testcase".

2. I wrote a procedure to do the xml parsing and insertion of data into table which I is under procedure1 in the code snippet below.

3. I wrote a procedure to call the above procedure with "testdata" column value of each row.

4. The first procedure is called xml_proc and the second procedure is called tcupdate.

whne I run "Exec tcupdate", the procudure runs fine and say " PL/SQL Procedure ran successfully", but I don't get any result.

Any help is appreciated.
Procedure1:
 
CREATE OR REPLACE PROCEDURE HITOOLS2.xml_proc (p_xml IN CLOB,tid IN NUMBER) AS
      l_parser    dbms_xmlparser.Parser;
      l_doc       dbms_xmldom.DOMDocument;
      l_nl        dbms_xmldom.DOMNodeList;
      l_n         dbms_xmldom.DOMNode;
      
     
      
      
      l_expa VARCHAR2(100) :='';
      f_expa VARCHAR2(500) :='';
      
      
    BEGIN
 
      -- Create a parser.
      l_parser := dbms_xmlparser.newParser;
 
      -- Parse the document and create a new DOM document.
      dbms_xmlparser.parseClob(l_parser, p_xml);
      l_doc := dbms_xmlparser.getDocument(l_parser);
 
      -- Get a list of all the TABLE nodes in the document using the XPATH syntax.
      l_nl := dbms_xslprocessor.selectNodes(dbms_xmldom.makeNode(l_doc),'/Test/Expected_After/Match');
 
      -- Loop through the list and display the contents
      FOR cur_tab IN 0 .. dbms_xmldom.getLength(l_nl) - 1 LOOP
        l_n := dbms_xmldom.item(l_nl, cur_tab);
        
        --prc status and prc mode
 
        dbms_xslprocessor.valueOf(l_n,'text()',l_expa);
        
        f_expa := f_expa || ',' || l_expa;
        
      END LOOP;
      
      UPDATE TESTCASE SET EXPECTAFTER = f_expa where testcase_id = tid;
 
      -- Free resources.
      dbms_xmldom.freeDocument(l_doc);
      dbms_xmlparser.freeParser(l_parser);
    EXCEPTION
      WHEN OTHERS THEN
        dbms_xmldom.freeDocument(l_doc);
        dbms_xmlparser.freeParser(l_parser);
        RAISE;
    END;
/
 
-----------------------------------------------------------------------------------------------------------------
Procedure 2:
 
CREATE OR REPLACE PROCEDURE HITOOLS2.tcupdate AS
 
   cursor c is
    select testdata,testcase_id FROM TESTCASE;
 
BEGIN
   FOR r IN c loop
      xml_proc(r.testdata,r.testcase_id);
   END LOOP;
exception when others then
   dbms_output.put_line('error: '||sqlerrm);
END;
/

Open in new window

Avatar of shru_0409
shru_0409
Flag of India image

Avatar of flow01
If running sqlplus to execute the procedure you wil not get any output from dbms_output if you dont
enable dbms_output

You can add extra dbms_output to debug your procedure

CREATE OR REPLACE PROCEDURE HITOOLS2.tcupdate AS
 
   cursor c is
    select testdata,testcase_id FROM TESTCASE;
 
BEGIN
   dbms_output.put_line('1');
  FOR r IN c loop
   dbms_output.put_line('2:' || r_testcase_id);
     xml_proc(r.testdata,r.testcase_id);
   END LOOP;
exception when others then
   dbms_output.put_line('error: '||sqlerrm);
END;
/


set serveroutput on
exec tcupdate

Avatar of jgudavalli
jgudavalli

ASKER

Hi flow01,
I did the exact same thing as you said. It didn't gice any output. It just ran for five seconds or less and said "PL/SQL procedure successfully completed".

What could be wrong. Is the procedure running at all?

Thanks,
Jyothi
You set serveroutput on and the  '1'  of the first  dbms_output.put_line('1'); didn't show ?

are you running it as user  HITOOLS2 ?
Hi Flow01,
It did give me some output. but after readin 8 rows as below, it says user buffer too small.
Please note on test machine I have 57000 rows and on prodcution we have 100,000 rows. how can we overcome this buffer overflow?

1
2:345
2:346
2:201
2:202
2:204
2:1203212886305
2:1222169331443
error: ORA-24331: user buffer too small
PL/SQL procedure successfully completed.
I did answer another problem where only 400 rows existed

A)
the dbms_output size is limited but can get raised to 100000

set serveroutput on size 100000

B)
there is a maximum string for dbms_output = 255
dbms_output.put_line(substr('2:' || r_testcase_id,1,255);

C) time to get the error only

CREATE OR REPLACE PROCEDURE HITOOLS2.tcupdate AS
 
   cursor c is
    select testdata,testcase_id FROM TESTCASE;
 
   v_id testcase.testcase_id%TYPE;
BEGIN
   dbms_output.put_line('1');
  FOR r IN c loop
     v_id := r.testcase_id;
     xml_proc(r.testdata,r.testcase_id);
   END LOOP;
exception when others then
   dbms_output.put_line('error id: '||v_id);
   dbms_output.put_line('error: '||sqlerrm);
END;
/
sorry , probably the error-message is to large

CREATE OR REPLACE PROCEDURE HITOOLS2.tcupdate AS
 
   cursor c is
    select testdata,testcase_id FROM TESTCASE;
 
   v_id testcase.testcase_id%TYPE;
BEGIN
   dbms_output.put_line('1');
  FOR r IN c loop
     v_id := r.testcase_id;
     xml_proc(r.testdata,r.testcase_id);
   END LOOP;
exception when others then
   dbms_output.put_line('error id: '||v_id);
   dbms_output.put_line(substr('error: '||sqlerrm,1,255);
   dbms_output.put_line('error part 2');
  dbms_output.put_line(substr('error: '||sqlerrm,256,255);
 END;
/
Hi Flow01,
It actually passed several step now. I see some rows getting updated.
However, there was another error now:

1
error id: 33302
error: ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00241: entity reference is not well formed
Error at line 6
PL/SQL procedure successfully completed.

further looking into the issue , I figured out that the tag <test> was not the only tag, it has <TestSet> as the parent tag.

I know I can use a if else loop for this. how can I tell the procudure to continue even if there is error at one row and collect all the testcaseid's (i.e the info of the rows ) for which it failed.

thanks much for your help and guidance.

Regards,
Jyothi
ASKER CERTIFIED SOLUTION
Avatar of flow01
flow01
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Flow01,
Thanks for the reply. However, I still cannot get the error message. But the PL?SQL ran successfully on all the rows except on 2000 rows out of which 934 rows need to updated. These 934 rows have <TestSet> as their root tag instead of <Test>. But the procedure didn't show these testcase id's on the console or throw any error.

I think I should accept your solution as I am very close to achieve the results. If you know how to get the
error testcase ids, let me know. Otherwise, I will accept your solution.

Regards,
Jyothi
Strange,
you did get a display of '1' indicating "set serveroutput on"  is activated ?
Excellent guidance. Thank you very much.