我是 Oracle XML 领域的新手。我正在尝试解析 XML,但没有做到。
下面是 XML 数据。
<CompositeDataObject Type="ApplicantsAAT" Version="0">
<DataObjectElement SystemName="AccountRelationship" ObjectType="DataObjectCollection">
<CollectionItem ID="604008" EncryptedID="4GnX1!b8epwsAmwbfvZjo;xAAAAAB6r2wy" DataObjectCategory="RepeatingAttribute" DataObjectType="AccountRelationshipAAT"/>
<CollectionItem ID="604040" EncryptedID="4IrPkqeoo7EVLEuSm7egK96AAAAAB6r2zS" DataObjectCategory="RepeatingAttribute" DataObjectType="AccountRelationshipAAT"/>
</DataObjectElement>
<DataObjectElement SystemName="ApplicantCreditRefDetailsAATSL" ObjectType="DataObject" ID="603979" EncryptedID="4PPEFaEyt2Q!K48f13wy7gzAAAAAB6r2wR" DataObjectCategory="RepeatingAttribute" DataObjectType="ApplicantCreditRefDetailsAATSL"/><DataObjectElement SystemName="CreditCardsTPF" ObjectType="DataObjectCollection"/><CompositeDataObjectElement SystemName="CreditObligations" ObjectType="DataObjectCollection"/><DataObjectElement SystemName="CreditScoring" ObjectType="DataObject" ID="603970" EncryptedID="4CWx;PRGqbV1IMzP4DtnY2IAAAAAB6r2wY" DataObjectCategory="RepeatingAttribute" DataObjectType="CreditScoring"/><DataObjectElement SystemName="DependantDetails" ObjectType="DataObject" ID="603978" EncryptedID="4OReRldXZeF8IU9a2e3RZk9AAAAAB6r2wQ" DataObjectCategory="RepeatingAttribute" DataObjectType="ApplicantDependantDetailsAATSL"/><DataObjectElement SystemName="EmploymentAATSL" ObjectType="DataObject" ID="603972" EncryptedID="4GkF83Ll!xLiLqS1zL;FMG4AAAAAB6r2we" DataObjectCategory="RepeatingAttribute" DataObjectType="EmploymentAperioOnlyAATSL"/><DataObjectElement SystemName="ExpenditureDetailsTPF" ObjectType="DataObject" ID="603980" EncryptedID="4G6EGC6aL8LmN94xr9LNgRxAAAAAB6r2wW" DataObjectCategory="RepeatingAttribute" DataObjectType="ExpenditureTPF"/><DataObjectElement SystemName="Fields" ObjectType="DataObject" ID="9251" EncryptedID="4MEw5;;AiwprG2uKYJGudrLAAAAAB6pn95" DataObjectCategory="Party" DataObjectType="Personal"/><DataObjectElement SystemName="FinancialAssetsAATSL" ObjectType="DataObjectCollection"/><DataObjectElement SystemName="FinancialExpenseAATSL" ObjectType="DataObjectCollection"/><DataObjectElement SystemName="FinancialLiabilitiesAATSL" ObjectType="DataObjectCollection"/><DataObjectElement SystemName="FinancierDeductionAATSL" ObjectType="DataObjectCollection"/><DataObjectElement SystemName="IncomeSalariedAATSL" ObjectType="DataObject" ID="603973" EncryptedID="4J04bAAaMKqPIXbr7AAUfoQAAAAAB6r2wf" DataObjectCategory="RepeatingAttribute" DataObjectType="ApplicantFinancialIncomeSalariedFinalAATSL"/><DataObjectElement SystemName="IncomeSelfEmployedAATSL" ObjectType="DataObject" ID="603974" EncryptedID="4D;pvvFrYPDyLjkipR7sYyQAAAAAB6r2wc" DataObjectCategory="RepeatingAttribute" DataObjectType="ApplicantFinancialIncomeSelfEmplAATAP"/>
<CompositeDataObjectElement SystemName="Tabs" ObjectType="DataObject" ID="378409" EncryptedID="4J!pTqS7x4XxIYZjRd2jA2UAAAAAB6o51z" CompositeDataObject="ApplicantsViewsAAT"/>
</CompositeDataObject>
CollectionItem
如果内部仅存在一次,则以下查询可以正常工作DataObjectElement
。如果collectionItem
出现不止一次,则失败。基本上我想要实现的是在看到标签 ID 时将数据考虑到新行中。
WITH t AS (SELECT XMLType('<CompositeDataObject Type="ApplicantsAAT" Version="0">
<DataObjectElement SystemName="AccountRelationship" ObjectType="DataObjectCollection">
<CollectionItem ID="604008" EncryptedID="4GnX1!b8epwsAmwbfvZjo;xAAAAAB6r2wy" DataObjectCategory="RepeatingAttribute" DataObjectType="AccountRelationshipAAT"/>
<CollectionItem ID="604040" EncryptedID="4IrPkqeoo7EVLEuSm7egK96AAAAAB6r2zS" DataObjectCategory="RepeatingAttribute" DataObjectType="AccountRelationshipAAT"/>
</DataObjectElement>
<DataObjectElement SystemName="ApplicantCreditRefDetailsAATSL" ObjectType="DataObject" ID="603979" EncryptedID="4PPEFaEyt2Q!K48f13wy7gzAAAAAB6r2wR" DataObjectCategory="RepeatingAttribute" DataObjectType="ApplicantCreditRefDetailsAATSL"/><DataObjectElement SystemName="CreditCardsTPF" ObjectType="DataObjectCollection"/><CompositeDataObjectElement SystemName="CreditObligations" ObjectType="DataObjectCollection"/><DataObjectElement SystemName="CreditScoring" ObjectType="DataObject" ID="603970" EncryptedID="4CWx;PRGqbV1IMzP4DtnY2IAAAAAB6r2wY" DataObjectCategory="RepeatingAttribute" DataObjectType="CreditScoring"/><DataObjectElement SystemName="DependantDetails" ObjectType="DataObject" ID="603978" EncryptedID="4OReRldXZeF8IU9a2e3RZk9AAAAAB6r2wQ" DataObjectCategory="RepeatingAttribute" DataObjectType="ApplicantDependantDetailsAATSL"/><DataObjectElement SystemName="EmploymentAATSL" ObjectType="DataObject" ID="603972" EncryptedID="4GkF83Ll!xLiLqS1zL;FMG4AAAAAB6r2we" DataObjectCategory="RepeatingAttribute" DataObjectType="EmploymentAperioOnlyAATSL"/><DataObjectElement SystemName="ExpenditureDetailsTPF" ObjectType="DataObject" ID="603980" EncryptedID="4G6EGC6aL8LmN94xr9LNgRxAAAAAB6r2wW" DataObjectCategory="RepeatingAttribute" DataObjectType="ExpenditureTPF"/><DataObjectElement SystemName="Fields" ObjectType="DataObject" ID="9251" EncryptedID="4MEw5;;AiwprG2uKYJGudrLAAAAAB6pn95" DataObjectCategory="Party" DataObjectType="Personal"/><DataObjectElement SystemName="FinancialAssetsAATSL" ObjectType="DataObjectCollection"/><DataObjectElement SystemName="FinancialExpenseAATSL" ObjectType="DataObjectCollection"/><DataObjectElement SystemName="FinancialLiabilitiesAATSL" ObjectType="DataObjectCollection"/><DataObjectElement SystemName="FinancierDeductionAATSL" ObjectType="DataObjectCollection"/><DataObjectElement SystemName="IncomeSalariedAATSL" ObjectType="DataObject" ID="603973" EncryptedID="4J04bAAaMKqPIXbr7AAUfoQAAAAAB6r2wf" DataObjectCategory="RepeatingAttribute" DataObjectType="ApplicantFinancialIncomeSalariedFinalAATSL"/><DataObjectElement SystemName="IncomeSelfEmployedAATSL" ObjectType="DataObject" ID="603974" EncryptedID="4D;pvvFrYPDyLjkipR7sYyQAAAAAB6r2wc" DataObjectCategory="RepeatingAttribute" DataObjectType="ApplicantFinancialIncomeSelfEmplAATAP"/>
<CompositeDataObjectElement SystemName="Tabs" ObjectType="DataObject" ID="378409" EncryptedID="4J!pTqS7x4XxIYZjRd2jA2UAAAAAB6o51z" CompositeDataObject="ApplicantsViewsAAT"/>
</CompositeDataObject>') xmlcol
FROM dual)
SELECT extract(value(x),'//*[@ID]/@ID') linked_object_id,
extractValue(value(x),'//*[@ID]/ancestor-or-self::*[@EncryptedID]/@EncryptedID') linked_object_encrypted_id,
extractValue(value(x),'//*[@ID]/ancestor-or-self::*[@SystemName]/@SystemName') system_name,
extractValue(value(x),'//*[@ID]/ancestor-or-self::*[@DataObjectCategory]/@DataObjectCategory') data_object_category,
extractValue(value(x),'//*[@ID]/ancestor-or-self::*[@ObjectType]/@ObjectType') object_type,
extractValue(value(x),'//*[@ID]/ancestor-or-self::*[@DataObjectType]/@DataObjectType') data_object_type,
extractValue(value(x),'//*[@ID]/ancestor-or-self::*[@CompositeDataObject]/@CompositeDataObject') composite_data_object
FROM t, TABLE(XMLSequence(extract(t.xmlcol,'/CompositeDataObject/*'))) x;
====================================== 下面是我期待的简单示例
感谢您的宝贵回复。
您发布的查询工作正常。但正如您所看到的,有些字段生成为 NULL。例如。第一个 DataObjectElement 包含 2 个 CollectionItem(604008,604008a),但 CollectionItem 中没有“SystemName”,所以我期待主 DataObjectElement 标记中的 SystemName .. 即“AccountRelationship”。对象类型也是如此
WITH t AS (SELECT XMLType('<CompositeDataObject Type="ApplicantsAAT" Version="0">
<DataObjectElement SystemName="AccountRelationship" ObjectType="DataObjectCollection">
<CollectionItem ID="604008" EncryptedID="4GnX1!b8epwsAmwbfvZjo;xAAAAAB6r2wy" DataObjectCategory="RepeatingAttribute" DataObjectType="AccountRelationshipAAT"/>
<CollectionItem ID="604008a" EncryptedID="4GnX1!b8epwsAmwbfvZjo;xAAAAAB6r2wy" DataObjectCategory="RepeatingAttribute" DataObjectType="AccountRelationshipAAT"/>
</DataObjectElement>
<DataObjectElement SystemName="ApplicantCreditRefDetailsAATSL" ObjectType="DataObject" ID="603979" EncryptedID="4PPEFaEyt2Q!K48f13wy7gzAAAAAB6r2wR" DataObjectCategory="RepeatingAttribute" DataObjectType="ApplicantCreditRefDetailsAATSL"/>
<CompositeDataObjectElement SystemName="Tabs" ObjectType="DataObject" ID="378409" EncryptedID="4J!pTqS7x4XxIYZjRd2jA2UAAAAAB6o51z" CompositeDataObject="ApplicantsViewsAAT"/>
</CompositeDataObject>') xmlcol
FROM dual)
SELECT extractvalue(value(x), '/*/@ID') id,
extractvalue(value(x), '/*/@EncryptedID') EncryptedID,
extractvalue(value(x), '/*/@SystemName') SystemName,
extractvalue(value(x), '/*/@DataObjectCategory') DataObjectCategory,
extractvalue(value(x), '/*/@ObjectType') ObjectType,
extractvalue(value(x), '/*/@DataObjectType') DataObjectType,
extractvalue(value(x), '/*/@CompositeDataObject') CompositeDataObject
FROM t, TABLE(XMLSequence(extract(t.xmlcol,'//*[@ID]'))) x;
上述查询的结果是
ID ENCRYPTEDID SYSTEMNAME DATAOBJECTCATEGORY OBJECTTYPE DATAOBJECTTYPE COMPOSITEDATAOBJECT
604008 4GnX1!b8epwsAmwbfvZjo;xAAAAAB6r2wy RepeatingAttribute AccountRelationshipAAT
604008a 4GnX1!b8epwsAmwbfvZjo;xAAAAAB6r2wy RepeatingAttribute AccountRelationshipAAT
603979 4PPEFaEyt2Q!K48f13wy7gzAAAAAB6r2wR ApplicantCreditRefDetailsAATSL RepeatingAttribute DataObject ApplicantCreditRefDetailsAATSL
378409 4J!pTqS7x4XxIYZjRd2jA2UAAAAAB6o51z Tabs DataObject ApplicantsViewsAAT
我期待的只是轻微的变化(下面的结果包含 SYSTEMNAME 和 OBJECTTYPE 的值)
ID ENCRYPTEDID SYSTEMNAME DATAOBJECTCATEGORY OBJECTTYPE DATAOBJECTTYPE COMPOSITEDATAOBJECT
604008 4GnX1!b8epwsAmwbfvZjo;xAAAAAB6r2wy AccountRelationship RepeatingAttribute DataObjectCollection AccountRelationshipAAT
604008a 4GnX1!b8epwsAmwbfvZjo;xAAAAAB6r2wy AccountRelationship RepeatingAttribute DataObjectCollection AccountRelationshipAAT
603979 4PPEFaEyt2Q!K48f13wy7gzAAAAAB6r2wR ApplicantCreditRefDetailsAATSL RepeatingAttribute DataObject ApplicantCreditRefDetailsAATSL
378409 4J!pTqS7x4XxIYZjRd2jA2UAAAAAB6o51z Tabs DataObject ApplicantsViewsAAT
请把我的内容复制到一些文本板中以获得更清晰的视图。非常感谢您的帮助