Home » Developer & Programmer » JDeveloper, Java & XML » Need to insert/update data from xml into tables.
Need to insert/update data from xml into tables. [message #171565] Wed, 10 May 2006 07:15 Go to next message
mb_geeta
Messages: 13
Registered: May 2006
Junior Member
Hi all,

I have an xml document from which i need to extraxt rows
and check each row with the table.If row exists,the record should be updated, else it should be inserted.Can any please suggest how to do this. This is very URGENT
Re: Need to insert/update data from xml into tables. [message #171935 is a reply to message #171565] Fri, 12 May 2006 06:34 Go to previous messageGo to next message
mb_geeta
Messages: 13
Registered: May 2006
Junior Member
I got it. I am closing the query
Re: Need to insert/update data from xml into tables. [message #172027 is a reply to message #171565] Sat, 13 May 2006 06:09 Go to previous messageGo to next message
gogula77
Messages: 52
Registered: January 2006
Location: Hyderabad
Member
Hi,

If you got the answer, then let all of us know that. It might be useful to somebody at some point of time.

So post the solution.

Regards

Gogula
Re: Need to insert/update data from xml into tables. [message #172112 is a reply to message #172027] Mon, 15 May 2006 00:02 Go to previous message
mb_geeta
Messages: 13
Registered: May 2006
Junior Member

All that we need to do is open the file(using UTL_FILE),read it into CLOB and convert into XMLTYPE instance.Then the following code works:
for i in ( select EXTRACTVALUE(VALUE(t), '/EMP/EMPNO') empno,
EXTRACTVALUE(VALUE(t), '/EMP/ENAME') ename,
EXTRACTVALUE(VALUE(t), '/EMP/JOB') job,
EXTRACTVALUE(VALUE(t), '/EMP/MGR') mgr,
EXTRACTVALUE(VALUE(t), '/EMP/HIREDATE') hiredate,
EXTRACTVALUE(VALUE(t), '/EMP/SAL') sal,
EXTRACTVALUE(VALUE(t), '/EMP/COMM') comm
FROM TABLE(XMLSEQUENCE(EXTRACT(x, '/EMPLOYEES/EMP'))) t )
--where x is the XMLTYPE instance.

loop

Update EMP set ENAME=i.ename where EMPNO=i.empno;
if SQL%NOTFOUND then
insert into EMPNO values (i.empno,i.ename,i.job,i.mgr,i.hiredate,i.sal,i.comm)
Previous Topic: running sql script in java
Next Topic: How to create a PDF from a JSP
Goto Forum:
  


Current Time: Fri Nov 22 05:38:56 CST 2024