[英]xml to oracle database
I have to import an xml file into an oracle data base, but the file have this structure : 我必须将xml文件导入到oracle数据库中,但是该文件具有以下结构:
tasks: 任务:
xml file: xml文件:
<root>
<customers>
<customer id=1>e-mag</customer>
<customer id=2>Eurofigher</customer>
</customers>
<customer_invoices>
<invoice id=1>
<customer_id>1</customer_id>
<items>
<item id=1 unit_value=10 tva=21 units=5>Laptop</item>
<item id=2 unit_value=20 tva=21 units=3>Monitors</item>
</items>
</invoice>
</customer_invoices>
</root>
What is the best way to do that? 最好的方法是什么? Please help me. 请帮我。
If you want to import them in an relational structure. 如果要以关系结构导入它们。 First load it into a XMLTYPE column 首先将其加载到XMLTYPE列中
DROP TABLE XMLTEST;
CREATE TABLE XMLTEST
( XML_COL XMLTYPE);
DECLARE
poXML CLOB;
BEGIN
-- Store the Purchase Order XML in the CLOB variable
poXML := '<?xml version="1.0"?>
<rooms>
<room room_id="1">
<alt_id>88</alt_id>
<display_naam>01 West 430</display_naam>
<alt_db>eXpress_BK</alt_db>
</room>
<room room_id="2">
<alt_id>170</alt_id>
<display_naam>02 Midden 010</display_naam>
<alt_db>eXpress_BK</alt_db>
</room>
<room room_id="3">
<alt_id>173</alt_id>
<display_naam>02 Midden 110</display_naam>
<alt_db>eXpress_BK</alt_db>
</room>
<room room_id="4">
<sil_id>F491B0A119DABE76B2F6B2C0A3E902F6</sil_id>
<alt_id>183</alt_id>
<display_naam>02 Oost 010</display_naam>
<alt_db>eXpress_BK</alt_db>
</room>
<room room_id="5">
<alt_id>172</alt_id>
<display_naam>02 Oost 300</display_naam>
<alt_db>eXpress_BK</alt_db>
</room>
.
.
.
<room room_id="126">
<sil_id>F491B0A119DABE76B2F6B2C0A3E901E3</sil_id>
<alt_id>129</alt_id>
<display_naam>HB.02.140</display_naam>
<alt_db>eXpress_EWI</alt_db>
</room>
</rooms>';
INSERT INTO xmltest (xml_col) VALUES (XMLTYPE(poXML));
END;
Then create a table based ont the XML structure 然后基于XML结构创建一个表
drop table rooms;
create table rooms as
select xt.room_id
, xt.alt_id
, xt.sil_id
, xt.alt_db
, xt.display_naam
from xmltest xts
, XMLTable('rooms/room' PASSING xts.xml_col
columns room_id INTEGER PATH '@room_id'
,alt_id INTEGER PATH 'alt_id'
,sil_id VARCHAR2(100) PATH 'sil_id'
,display_naam VARCHAR2(100)PATH 'display_naam'
,alt_db VARCHAR2(100)PATH 'alt_db') xt;
I think you will have to create three create table statements. 我认为您将必须创建三个create table语句。 One for customers and one for customer_invoices and one form cursomer_invoice_items as they clearly don't fit in one relational table. 一种用于客户,一种用于customer_invoices,一种形式为cursomer_invoice_items,因为它们显然不适合一个关系表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.