我正在尝试使用xml文件创建一个用列分隔的oracle表。 我使用sql命令创建表:
create table mytable of XMLType;
insert into mytable2 values(XMLType(bfilename('XMLDIR','XMLFileName.xml'),nls_charset_id('AL32UTF8')));
该文件以xml结构插入到表中,但我需要在列中查看或仅在令牌ct:iid之后选择字段到标记中。 例如,在第一个标签中,我需要选择值“OrphanedBSCs”。
<?xml version="1.0" encoding="WINDOWS-1252"?>
<ArrayOfRootEntityType xmlns:umts="http://www.aircominternational.com/Schemas/UMTS/2010/07" xmlns:tra70="http://www.aircominternational.com/Schemas/Connect/2010/08" xmlns:ct="http://www.aircominternational.com/Schemas/CommonTypes/2009/05" xmlns:co="http://www.aircominternational.com/Schemas/Common/2009/07" xmlns:gsm80="http://www.aircominternational.com/Schemas/GSM/2011/04" xmlns:ecs="http://www.aircominternational.com/Schemas/EWS/ECSCoverageTypes/2011/08" xmlns:gsm70="http://www.aircominternational.com/Schemas/GSM/2010/08" xmlns:config="http://www.aircominternational.com/Schemas/Configuration/2010/08" xmlns:cdma="http://www.aircominternational.com/Schemas/CDMA/2010/12" xmlns:co70="http://www.aircominternational.com/Schemas/Common/2010/08" xmlns:umts80="http://www.aircominternational.com/Schemas/UMTS/2011/04" xmlns:eqp70="http://www.aircominternational.com/Schemas/Equipment/2010/08" xmlns:co80="http://www.aircominternational.com/Schemas/Common/2011/04" xmlns:util="http://www.aircominternational.com/contract/Util/2009/10" xmlns:tra80="http://www.aircominternational.com/Schemas/Connect/2011/04" xmlns:umts70="http://www.aircominternational.com/Schemas/UMTS/2010/08" xmlns:eqp80="http://www.aircominternational.com/Schemas/Equipment/2011/04" xmlns:tra="http://www.aircominternational.com/Schemas/Connect/2009/09" xmlns:lte="http://www.aircominternational.com/Schemas/LTE/2010/08" xmlns:eds="http://www.aircominternational.com/contract/EDS/2009/05" xmlns:umts2="http://www.aircominternational.com/Schemas/UMTS/2009/05" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:eqp="http://www.aircominternational.com/Schemas/Equipment/2009/09" xmlns:gsm="http://www.aircominternational.com/Schemas/GSM/2009/09" xmlns:lte80="http://www.aircominternational.com/Schemas/LTE/2011/04">
<RootEntityType xsi:type="gsm:MSCType" ct:iid="OrphanedBSCs" ct:bvid="IVLP_201303" ct:eid="223127">
<Security>
<CreateDate>2013-03-21T10:01:18</CreateDate>
<ModifyDate>2013-03-21T10:01:19</ModifyDate>
<CreateUser>EDS_SOA_Client</CreateUser>
<ModifyUser>EDS_SOA_Client</ModifyUser>
<UserGroup>All</UserGroup>
<Permissions>
<Owner>write</Owner>
<Group>write</Group>
<All>read</All>
</Permissions>
</Security>
<CustomFields>
<Field Group="SOURCE" Value="NETWORK"/>
<Field Group="LastUpdated" Value="3/21/2013 10:01:18 AM"/>
</CustomFields>
<Location ct:iid="OrphanedBSCs_msc_loc" ct:eid="119692"/>
<gsm:BSCs>
<gsm:BSC ct:iid="OrphanedSites" ct:bvid="IVLP_201303" ct:eid="223128">
<Security>
<CreateDate>2013-03-21T10:01:19</CreateDate>
<ModifyDate>2013-03-21T10:01:19</ModifyDate>
<CreateUser>EDS_SOA_Client</CreateUser>
<ModifyUser>EDS_SOA_Client</ModifyUser>
<UserGroup>All</UserGroup>
<Permissions>
<Owner>write</Owner>
<Group>write</Group>
<All>read</All>
</Permissions>
</Security>
<CustomFields>
<Field Group="SOURCE" Value="NETWORK"/>
<Field Group="LastUpdated" Value="3/21/2013 10:01:19 AM"/>
</CustomFields>
<Location ct:iid="OrphanedSites_bsc_loc" ct:eid="119693"/>
<gsm:Parent ct:iid="OrphanedBSCs" ct:eid="223127"/>
<gsm:BSCId>0</gsm:BSCId>
<gsm:AllowedOperations>ReadWrite</gsm:AllowedOperations>
</gsm:BSC>
</gsm:BSCs>
<gsm:AllowedOperations>ReadWrite</gsm:AllowedOperations>
</RootEntityType>
<RootEntityType xsi:type="gsm:MSCType" ct:iid="HUAWEI_2G_MSC" ct:bvid="IVLP_201303" ct:eid="223131">
<Security>
<CreateDate>2013-03-21T10:01:21</CreateDate>
<ModifyDate>2013-03-21T10:01:21</ModifyDate>
<CreateUser>EDS_SOA_Client</CreateUser>
<ModifyUser>EDS_SOA_Client</ModifyUser>
<UserGroup>All</UserGroup>
<Permissions>
<Owner>write</Owner>
<Group>write</Group>
<All>read</All>
</Permissions>
</Security>
<CustomFields>
<Field Group="SOURCE" Value="NETWORK"/>
<Field Group="LastUpdated" Value="3/21/2013 10:01:21 AM"/>
</CustomFields>
<Location ct:iid="HUAWEI_2G_MSC_msc_loc" ct:eid="119696"/>
<gsm:BSCs>
<gsm:BSC ct:iid="BSCMG35" ct:bvid="IVLP_201303" ct:eid="223252">
<Security>
<CreateDate>2013-03-21T10:01:30</CreateDate>
<ModifyDate>2013-03-21T10:01:30</ModifyDate>
<CreateUser>EDS_SOA_Client</CreateUser>
<ModifyUser>EDS_SOA_Client</ModifyUser>
<UserGroup>All</UserGroup>
<Permissions>
<Owner>write</Owner>
<Group>write</Group>
<All>read</All>
</Permissions>
</Security>
<CustomFields>
<Field Group="SOURCE" Value="NETWORK"/>
<Field Group="LastUpdated" Value="3/21/2013 10:01:22 AM"/>
</CustomFields>
<Location ct:iid="BSCMG35_bsc_loc" ct:eid="119817"/>
<gsm:Parent ct:iid="HUAWEI_2G_MSC" ct:eid="223131"/>
<gsm:BSCId>0</gsm:BSCId>
<gsm:AllowedOperations>ReadWrite</gsm:AllowedOperations>
</gsm:BSC>
<gsm:BSC ct:iid="BSCMG34" ct:bvid="IVLP_201303" ct:eid="223270">
<Security>
<CreateDate>2013-03-21T10:01:30</CreateDate>
<ModifyDate>2013-03-21T10:01:30</ModifyDate>
<CreateUser>EDS_SOA_Client</CreateUser>
<ModifyUser>EDS_SOA_Client</ModifyUser>
<UserGroup>All</UserGroup>
<Permissions>
<Owner>write</Owner>
<Group>write</Group>
<All>read</All>
</Permissions>
</Security>
<CustomFields>
<Field Group="SOURCE" Value="NETWORK"/>
<Field Group="LastUpdated" Value="3/21/2013 10:01:22 AM"/>
</CustomFields>
<Location ct:iid="BSCMG34_bsc_loc" ct:eid="119835"/>
<gsm:Parent ct:iid="HUAWEI_2G_MSC" ct:eid="223131"/>
<gsm:BSCId>0</gsm:BSCId>
<gsm:AllowedOperations>ReadWrite</gsm:AllowedOperations>
</gsm:BSC>
</gsm:BSCs>
<gsm:AllowedOperations>ReadWrite</gsm:AllowedOperations>
</RootEntityType>
</ArrayOfRootEntityType>
答案 0 :(得分:1)
使用类似的东西:
select *
from table-with-xml-column t
, xmltable
( 'PATH/TO/WHAT/YOU/NEED'
passing t.xml_column_name
columns column1 number path 'path1'
columns column2 char(1 byte) path 'path2'
columns column3 varchar2(30) path 'path3'
) t2
提示!请注意,处理XML列可能会非常缓慢,Oracle似乎经常解析xmltype的内容。不要在XML和内容的实际大小的情况下测试性能,不要在XML和关系数据或高频率执行的语句中引入复杂的连接。
答案 1 :(得分:0)
感谢您的帮助。 我解决了设置xml文件中使用的命名空间的问题。 这是在xml中选择任何数据的新查询:
选择* 来自table-with-xml-column t ,xmltable ( (XMLNAMESPACES('url_indicated_in_xmlfile_about_ct'as“ct”), 'PATH / TO /什么/你/ NEED' 传递t.xml_column_name 列column1编号路径'path1' columns column2 char(1字节)path'path2' columns column3 varchar2(30)path'path3' )t2