Which method is performance oriented in parsing the XML and perform DML Operations using PL/SQL in Oracle?
I came across different methods while parsing the XML in PL/SQL procedures like
First Way:
CURSOR datahold_xml(student_xmldoc IN xmltype) IS
SELECT extractvalue(value(t), '/Student/@Enrolled') Enrolled,
extractvalue(value(t), '/Student/SID') StudentID,
FROM TABLE(xmlsequence(extract(student_xmldoc , '/Student'))) t;
FOR tempresult_xml IN datahold_xml(student_xmldoc => l_xml) LOOP
IF UPPER(tempresult_xml.Enrolled) = UPPER('TRUE') THEN
/* Update Employee Information*/
UPDATE STUDENTTABLE st
SET st.firstname = tempresult_xml.FirstName,
st.lastname = tempresult_xml.LastName
WHERE st.SID= tempresult_xml.StudentID;
ELSE
/* Do Insert Operation*/
INSERT INTO STUDENTTABLE (SID,FIRSTNAME,LASTNAME,STATUS)
VALUES
(STUDENT_SEQ.NEXTVAL,tempresult_xml.FirstName, tempresult_xml.LastName,'A');
END IF;
END LOOP;
The other one is using XSL Processor like
indoc := '<Student Enrolled="TRUE">
<SID>1</SID>
</Student>
<Student Enrolled="FALSE">
<SID>1</SID>
<FirstName>James</FirstName>
<LName>Cameron</LName>
</Student>';
indomdoc := dbms_xmldom.newDomDocument(indoc);
l_nl := dbms_xslprocessor.selectNodes(dbms_xmldom.makeNode(indomdoc),
'//STUDENT[@Enrolled="TRUE"]');
/* Loop to Update Student Information */
FOR cur_stu IN 0 .. dbms_xmldom.getLength(l_nl) - 1 LOOP
l_n := dbms_xmldom.item(l_nl, cur_stu);
stu_tab.extend;
stu_tab(stu_tab.first).FIRSTNAME := dbms_xslprocessor.valueOf(l_n,
'FirstName/text()');
stu_tab(stu_tab.first).LASTNAME := dbms_xslprocessor.valueOf(l_n,
'LName/text()');
stu_tab(stu_tab.first).SID := dbms_xslprocessor.valueOf(l_n,
'ID/text()');
/* Update Student Information*/
UPDATE STUDENTTABLE st
SET st.firstname = stu_tab(1).FIRSTNAME,
st.lastname = stu_tab(1).LASTNAME
WHERE es.SID= stu_tab(1).SID;
END LOOP;
Which of the above methods yield better performan开发者_JS百科ce, using the cursors or xsl processor and DOM.
Please do let me know if there are any other better solutions available to parse the XML.
I am new to ORACLE and Hence in the process of learning..Wanted to try out few methods and want to know which is the best.
Any help would be appreciated.
Thanks, Sameer.
We use xmltable to process xml-s in plsql. If you care about the performance try to measure it for yourself, there are different methods, one of them is autotrace.
精彩评论