oracle解析xml,带命令空间的节点获取

在xml里有两个解析xml的函数extractextractVALUE,这两个函数可以带两个参数,也可以带上个参数,第三个参数是命令空间,对于namespace_string,刚开始我也很疑惑,然后去网上找了很久的资料也没弄明白,因为没有范例,最后在自己的尝试下解决了,

extract官网API如下:

http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions052.htm#i1131042

extract官网API如下:

http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions052.htm#i1131042

样例xml报文如下:

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:euc="http://platform.nucleusconnect.com/wsdl/EUCServices">
  <soapenv:Header>
    <euc:AuthHeaderRequest>
      <userName>User1</userName>
      <Token>45df847e-c02e-64d4-f6a1-76a9c8f2c537</Token>
    </euc:AuthHeaderRequest>
  </soapenv:Header>
  <soapenv:Body>
    <euc:EUCRevisionNewOrderRequest>
      <header>
        <Department>Business Solution - Business Broadband</Department>
        <AcceptTNC>Yes</AcceptTNC>
        <TransactionId>FB000120170119181518436</TransactionId>
      </header>
      <body>
        <SalesOrderId>2017011914381897</SalesOrderId>
        <PlanType>Non-Residential CA Customised PIR</PlanType>
        <IsGovernment>N</IsGovernment>
        <EUCBaseInfo>
          <RSPCustomerRef>BBNC1000001230</RSPCustomerRef>
          <ServiceType>NEUC</ServiceType>
        </EUCBaseInfo>
        <AdditionalInfo/>
        <EndUserContact>
          <Salutation>Mrs</Salutation>
          <FirstName>rrrrrr</FirstName>
          <LastName>rrrrrr</LastName>
          <ContactNumber1>44444444</ContactNumber1>
          <ContactNumber2>44444444</ContactNumber2>
          <Email>www@qq.com.cn</Email>
        </EndUserContact>
        <SpecialRequest/>
        <InstContactInfo>
          <Salutation>Mrs</Salutation>
          <FirstName>rrrrrr</FirstName>
          <LastName>rrrrrr</LastName>
          <ContactNumber1>44444444</ContactNumber1>
          <ContactNumber2>44444444</ContactNumber2>
          <Email>www@qq.com.cn</Email>
        </InstContactInfo>
        <ONInstPref>
          <InstPrefDate>2017-02-04</InstPrefDate>
          <InstONTimeSlot>09:00-13:00</InstONTimeSlot>
        </ONInstPref>
        <EUCConfig>
          <ServicePortType>Gigabit Ethernet UTP (1Gbps) over GPON</ServicePortType>
          <NumOfServicePorts>2</NumOfServicePorts>
          <Layer2Option>IEEE802.1q</Layer2Option>
          <PIRDL>250</PIRDL>
          <PIRUL>250</PIRUL>
        </EUCConfig>
        <ServPortConfigInfoList>
          <ServicePort>A</ServicePort>
          <ServiceProfile>FB0001-BzHighBB_Ded-EUC-01</ServiceProfile>
          <CoS>D</CoS>
          <SVLAN>1022</SVLAN>
          <CIRDL>50</CIRDL>
          <CIRUL>50</CIRUL>
        </ServPortConfigInfoList>
        <ServPortConfigInfoList>
          <ServicePort>B</ServicePort>
          <ServiceProfile>FB0001-NR-SmartUC_Fixed-EUC-01</ServiceProfile>
          <CoS>A</CoS>
          <SVLAN>1049</SVLAN>
          <CIRDL>5</CIRDL>
          <CIRUL>5</CIRUL>
        </ServPortConfigInfoList>
      </body>
    </euc:EUCRevisionNewOrderRequest>
  </soapenv:Body>
</soapenv:Envelope>

直接获取节点或者节点值样例sql如下:

select extract(xmltype('<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:euc="http://platform.nucleusconnect.com/wsdl/EUCServices">
  <soapenv:Header>
    <euc:AuthHeaderRequest>
      <userName>User1</userName>
      <Token>45df847e-c02e-64d4-f6a1-76a9c8f2c537</Token>
    </euc:AuthHeaderRequest>
  </soapenv:Header>
  <soapenv:Body>
    <euc:EUCRevisionNewOrderRequest>
      <header>
        <Department>Business Solution - Business Broadband</Department>
        <AcceptTNC>Yes</AcceptTNC>
        <TransactionId>FB000120170119181518436</TransactionId>
      </header>
      <body>
        <SalesOrderId>2017011914381897</SalesOrderId>
      </body>
    </euc:EUCRevisionNewOrderRequest>
  </soapenv:Body>
</soapenv:Envelope>'),
                '/soapenv:Envelope/soapenv:Body/euc:EUCRevisionNewOrderRequest/body',
                'xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:euc="http://platform.nucleusconnect.com/wsdl/EUCServices"')
  from dual a
select extractVALUE(xmltype('<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:euc="http://platform.nucleusconnect.com/wsdl/EUCServices">
  <soapenv:Header>
    <euc:AuthHeaderRequest>
      <userName>User1</userName>
      <Token>45df847e-c02e-64d4-f6a1-76a9c8f2c537</Token>
    </euc:AuthHeaderRequest>
  </soapenv:Header>
  <soapenv:Body>
    <euc:EUCRevisionNewOrderRequest>
      <header>
        <Department>Business Solution - Business Broadband</Department>
        <AcceptTNC>Yes</AcceptTNC>
        <TransactionId>FB000120170119181518436</TransactionId>
      </header>
      <body>
        <SalesOrderId>2017011914381897</SalesOrderId>
      </body>
    </euc:EUCRevisionNewOrderRequest>
  </soapenv:Body>
</soapenv:Envelope>'),
                     '/soapenv:Envelope/soapenv:Body/euc:EUCRevisionNewOrderRequest/body/SalesOrderId',
                     'xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:euc="http://platform.nucleusconnect.com/wsdl/EUCServices"')
  from dual a
通过xmltable转换为表格sql样例如下:


SELECT *
  FROM XMLTABLE(XMLNAMESPACES('http://schemas.xmlsoap.org/soap/envelope/' AS
                              "soapenv1",
                              'http://platform.nucleusconnect.com/wsdl/EUCServices' AS
                              "euc1"),
                '$B/soapenv1:Envelope/soapenv1:Body/euc1:EUCRevisionNewOrderRequest/body'
                PASSING
                (select xmltype('<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:euc="http://platform.nucleusconnect.com/wsdl/EUCServices">
  <soapenv:Header>
    <euc:AuthHeaderRequest>
      <userName>User1</userName>
      <Token>45df847e-c02e-64d4-f6a1-76a9c8f2c537</Token>
    </euc:AuthHeaderRequest>
  </soapenv:Header>
  <soapenv:Body>
    <euc:EUCRevisionNewOrderRequest>
      <header>
        <Department>Business Solution - Business Broadband</Department>
        <AcceptTNC>Yes</AcceptTNC>
        <TransactionId>FB000120170119181518436</TransactionId>
      </header>
      <body>
        <SalesOrderId>2017011914381897</SalesOrderId>
      </body>
    </euc:EUCRevisionNewOrderRequest>
  </soapenv:Body>
</soapenv:Envelope>')
                   from dual a ) AS B COLUMNS SalesOrderId
                VARCHAR2(128) PATH '/body/SalesOrderId')


  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Oracle可以通过使用XMLType数据类型来解析XML数据。 以下是一个简单的例子,演示如何解析XML数据并从中提取值: 假设有一个包含XML数据的表,名为"xml_table",其中包含一个XML列名为"xml_data"。现在需要解析这个XML数据并从中提取值。 ```sql SELECT ExtractValue(XMLType(xml_data), '/root/element') AS Extracted_Value FROM xml_table; ``` 上述代码中,ExtractValue()函数用于从XML数据中提取值。第一个参数是XML数据类型,第二个参数是XPath表达式,用于指定要提取的元素或属性。 在此示例中,XPath表达式是"/root/element",它表示要提取XML数据根节点下名为"element"的元素的值。 注意,XPath表达式中的斜杠"/"表示元素的层级关系。例如,"/root/element"表示根节点下的"element"元素。 此外,可以使用XMLTable函数将XML数据转换为表格形式,并从中提取值。以下是一个示例: ```sql SELECT xt.Extracted_Value FROM xml_table x, XMLTable('/root/element' PASSING XMLType(x.xml_data) COLUMNS Extracted_Value VARCHAR2(100) PATH '.') xt; ``` 在此示例中,XMLTable()函数用于将XML数据转换为表格形式。第一个参数是XPath表达式,用于指定要提取的元素或属性。第二个参数是XML数据类型。第三个参数是列定义,用于指定要从XML数据中提取的列。 注意,XPath表达式中的点"."表示当前节点。在此示例中,XPath表达式"/root/element"将作为列定义中的路径参数传递,用于指定要提取的元素或属性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值