私はオラクルの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
が 内に 1 回だけ存在する場合に正常に機能します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」です。同じことが ObjectType にも当てはまります
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 AND 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
見やすくするために、私のコンテンツをテキストパッドにコピーしてください。あなたの助けは大歓迎です