2014-03-13 74 views
2

請幫助解決問題。如何使用XMLTABLE在Oracle表中插入XML屬性類型

我在同一個博客中驗證了以前的問題,但無法解決問題。

SELECT x.* --,--XXAR_CUST_ACCT_INT_TBL_S.nextval 
     FROM XMLTABLE ('for $i in $wh//NewCustomerToEBS, 
          $j in $i//SiteLine 
          $j in $i//ContactLine 
          return <deNormalizedWH>{$i}{$j}</deNormalizedWH>' 
     PASSING xmltype (y)  
      AS "wh" 
COLUMNS ATTRIBUTE2 VARCHAR2(20) path NewCustomerToEBS/@AccessoryFulfilmentOrg', 
CUSTOMER_TYPE_SITE   VARCHAR2(80) path 'SiteLine/@AccountType', 
CUSTOMER_NUMBER_CONTACT VARCHAR2(40) path 'ContactLine/@AccountNumber') x. 

當我嘗試在我的自定義過程來執行SELECT語句,我得到以下錯誤: 這是我的完整的XML文件,但參考我給了3列(分別來自頭,線和觸點) 。

DECLARE 
    P_XML_DATA CLOB; 
BEGIN 
P_XML_DATA := '<NewCustomersToEBS> <NewCustomerToEBS AccessoryFulfilmentOrg="TEST" AccountType="TEST1" AlternateEmail="[email protected]" BlindShippments="NHGSV" Classification="HXHB" ComplianceCustomer="SKBCS" CustomerCategory="IUYT" CustomerNumber="FGGD12" CustomerProspectCode="LKOU" CustomerType="LOUTR" EDISDQSegmentCustomer="LOUY" Email="HDEG" Fax="HHBGG" FreeOnBoardPoint="KJHTR" FreightTerms="LKJ" OrderType="HBHJBJ" OrganizationName="VEN" Phone="LKJU87" PriceList="knjj" ProfileClass="MJRFS" RequestDataType="JNCJA" RoutingWindow="OIJH" SalesChannel="MNJH" ShipSet="RDSA" ShippingWindow="LKOP" StoreLocations="EDCG" UPCLabletype="LKJUO" URLs="JXABHCBH"> <SiteLine AccountType="JHFJS" AlternateEmailAddress="SV" BillToAddressLine1="SVSF" BillToAddressLine2="HGG" BillToAddressLine3="DBH" BillToCity="BJKD" BillToCountry="BB" BillToPostalCode="2323" BillToProvinice="BD" BillToState="GSDG" CensusRegion="DH" Country="HH" CustomerProspectCode="43T" CustomerType="HFHF" ECSRetailStoreLocation="FHF" EDILocation="HFHF" Email="FHF" Fax="5656" FreeOnBoardPoint="NFN" FreightTerms="BC" OrderType="KKMCK" Phone="4756" ProfileClass="KBD" Region="LS" ResidentialAddress="SS" SalesPerson="SW" ShipMethod="BDGD" ShipToAddressLine1="RF" ShipToAddressLine2="ES" ShipToAddressLine3="SS" ShipToCity="FF" ShipToCountry="GG" ShipToPostalCode="76" ShipToProvince="MM" ShipToState="GG" SiteLocation="GGG" SiteNumber="977" StoreLocations="GKV" StoresDistributionCentre="RT" URLs="RRR"/> <SiteLine AccountType="LOKI" AlternateEmailAddress="JJS" BillToAddressLine1="KMKK" BillToAddressLine2="POKJ" BillToAddressLine3="KIJO" BillToCity="PL" BillToCountry="OKJ" BillToPostalCode="OU" BillToProvinice="PL" BillToState="MN" CensusRegion="NB" Country="JH" CustomerProspectCode="KH" CustomerType="LK" ECSRetailStoreLocation="MJ" EDILocation="CF" Email="GF" Fax="987" FreeOnBoardPoint="MN" FreightTerms="LG" OrderType="UY" Phone="23" ProfileClass="LE" Region="DE" ResidentialAddress="ER" SalesPerson="RT" ShipMethod="TY" ShipToAddressLine1="YU" ShipToAddressLine2="IU" ShipToAddressLine3="SD" ShipToCity="DF" ShipToCountry="FG" ShipToPostalCode="34" ShipToProvince="NH" ShipToState="HG" SiteLocation="JK" SiteNumber="98" StoreLocations="YT" StoresDistributionCentre="RE" URLs="EW"/> <ContactLine AccountNumber="123" Acknowledgement="GGG" Email="NB" FaxAreaCode="54" FaxNumber="456" FaxType="BB" FirstName="KJ" Invoices="HG" JobTitle="FD" LastName="DS" OrganizationName="VG" PhoneAreaCode="66" PhoneNumber="55" PhoneType="XX" ShipTo="XX"/><ContactLine AccountNumber="345" Acknowledgement="RT" Email="TT" FaxAreaCode="33" FaxNumber="22" FaxType="BC" FirstName="SS" Invoices="JH" JobTitle="HH" LastName="JJ" OrganizationName="JHG" PhoneAreaCode="57" PhoneNumber="99" PhoneType="90" ShipTo="MM"/> </NewCustomerToEBS></NewCustomersToEBS>'; 
    XXAR_CUSTOMER_INBOUND_PROC(P_XML_DATA); 
    commit; 
END; 

ORA-19114: XPST0003 - error during parsing the XQuery expression: 
LPX-00801: XQuery syntax error at 'j' 
3        $j in $i//ContactLine 
-        ^
ORA-06512: at "APPS.XXAR_CUSTOMER_INBOUND_PROC", line 8 
ORA-06512: at line 13 

請查看錯誤信息,讓我知道我在做什麼錯誤。

在此先感謝!

回答

0

$j in $i//SiteLine之後需要一個, - 這是導致錯誤的原因。

但你也用過$j兩次(這可能會工作,但會給出錯誤的結果)。
嘗試:

SELECT x.* 
     FROM XMLTABLE ('for $i in $wh//NewCustomerToEBS, 
          $j in $i//SiteLine, 
          $z in $i//ContactLine 
          return <deNormalizedWH>{$i}{$j}{$z}</deNormalizedWH>' 
     PASSING xmltype (y)  
      AS "wh" 
COLUMNS ATTRIBUTE2 VARCHAR2(20) path 'NewCustomerToEBS/@AccessoryFulfilmentOrg', 
CUSTOMER_TYPE_SITE   VARCHAR2(80) path 'SiteLine/@AccountType', 
CUSTOMER_NUMBER_CONTACT VARCHAR2(40) path 'ContactLine/@AccountNumber') x 

Here is a sqlfiddle demo