1

私はオラクルの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

見やすくするために、私のコンテンツをテキストパッドにコピーしてください。あなたの助けは大歓迎です

4

1 に答える 1

0

あなたが何を求めているのか完全にはわかりませんが、「ID」ごとに1行ですか?もしそうなら..

 10  select id, EncryptedID,
 11         nvl(SystemName, extractvalue(xmlcol, '//*[child::*/@ID="' || id || '"]/@SystemName')) SystemName,
 12         DataObjectCategory,
 13         nvl(ObjectType, extractvalue(xmlcol, '//*[child::*/@ID="' || id || '"]/@ObjectType')) ObjectType,
 14         DataObjectType,
 15         CompositeDataObject
 16    from (SELECT t.xmlcol, extractvalue(value(x), '/*/@ID') id,
 17                 extractvalue(value(x), '/*/@EncryptedID') EncryptedID,
 18                 extractvalue(value(x), '/*/@SystemName') SystemName,
 19                 extractvalue(value(x), '/*/@DataObjectCategory') DataObjectCategory,
 20                 extractvalue(value(x), '/*/@ObjectType') ObjectType,
 21                 extractvalue(value(x), '/*/@DataObjectType') DataObjectType,
 22                 extractvalue(value(x), '/*/@CompositeDataObject') CompositeDataObject
 23          FROM t, TABLE(XMLSequence(extract(t.xmlcol,'//*[@ID]'))) x)
 24  ;

ID         ENCRYPTEDID          SYSTEMNAME           DATAOBJECTCATEGORY   OBJECTTYPE           DATAOBJECTTYPE       COMPOSITEDATAOBJECT
---------- -------------------- -------------------- -------------------- -------------------- -------------------- --------------------
604008     4GnX1!b8epwsAmwbfvZj AccountRelationship  RepeatingAttribute   DataObjectCollection AccountRelationshipA
           o;xAAAAAB6r2wy                                                                      AT

604040     4IrPkqeoo7EVLEuSm7eg AccountRelationship  RepeatingAttribute   DataObjectCollection AccountRelationshipA
           K96AAAAAB6r2zS                                                                      AT

603979     4PPEFaEyt2Q!K48f13wy ApplicantCreditRefDe RepeatingAttribute   DataObject           ApplicantCreditRefDe
           7gzAAAAAB6r2wR       tailsAATSL                                                     tailsAATSL

603970     4CWx;PRGqbV1IMzP4Dtn CreditScoring        RepeatingAttribute   DataObject           CreditScoring
           Y2IAAAAAB6r2wY

603978     4OReRldXZeF8IU9a2e3R DependantDetails     RepeatingAttribute   DataObject           ApplicantDependantDe
           Zk9AAAAAB6r2wQ                                                                      tailsAATSL

603972     4GkF83Ll!xLiLqS1zL;F EmploymentAATSL      RepeatingAttribute   DataObject           EmploymentAperioOnly
           MG4AAAAAB6r2we                                                                      AATSL

603980     4G6EGC6aL8LmN94xr9LN ExpenditureDetailsTP RepeatingAttribute   DataObject           ExpenditureTPF
           gRxAAAAAB6r2wW       F

9251       4MEw5;;AiwprG2uKYJGu Fields               Party                DataObject           Personal
           drLAAAAAB6pn95

603973     4J04bAAaMKqPIXbr7AAU IncomeSalariedAATSL  RepeatingAttribute   DataObject           ApplicantFinancialIn
           foQAAAAAB6r2wf                                                                      comeSalariedFinalAAT
                                                                                               SL

603974     4D;pvvFrYPDyLjkipR7s IncomeSelfEmployedAA RepeatingAttribute   DataObject           ApplicantFinancialIn
           YyQAAAAAB6r2wc       TSL                                                            comeSelfEmplAATAP

378409     4J!pTqS7x4XxIYZjRd2j Tabs                                      DataObject                                ApplicantsViewsAAT
           A2UAAAAAB6o51z
于 2013-01-04T21:04:13.890 に答える