如何使用XMLTABLE Type在oracle表中插入XML属性

时间:2014-03-13 07:18:01

标签: sql oracle xmltable

请帮助解决问题。

我在同一博客中验证了以前的问题,但无法解决问题。

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="syad@tek.com" 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

请查看错误消息,让我知道我在哪里做错了。

提前致谢!!

1 个答案:

答案 0 :(得分: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