简体   繁体   English

从Oracle中的XML列中提取值

[英]Extracting values from XML column in Oracle

I have some data in an Oracle table which is stored in an XML-format string (column response in table WS_LOG ). 我在Oracle表中有一些数据,该数据存储在XML格式的字符串中(表WS_LOGresponse )。

I would like to extract data from each different node below <MedicalProcedureOutput> , but I'm having some difficulties in getting to each of the nodes. 我想从<MedicalProcedureOutput>下的每个不同节点提取数据,但是在到达每个节点时遇到了一些困难。 Can you spot what I'm doing wrong? 你能发现我在做什么错吗?

Here's what I'm trying (here trying to retrieve the value for the icpcID tag): 这是我正在尝试的方法(这里尝试检索icpcID标签的值):

 SELECT a.id,
  t1.icpcID FROM
  GH.WS_LOG a, 
  xmltable(
  xmlnamespaces(
'http://schemas.xmlsoap.org/soap/envelope/' as "soap",
'http://www.w3.org/2001/XMLSchema' as "xsd",
'http://www.w3.org/2001/XMLSchema-instance' as "xsi"),
'/soap:Envelope/soap:Body/createBillingSubmissionForAFEBSGResponse/createBillingSubmissionForAFEBSGResult/proceduresList/MedicalProcedureOutput' passing xmltype(a.response) columns
icpcID varchar2(50) path 'ipcdId') t1

And here's some example data 这是一些示例数据

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soap:Body>
      <createBillingSubmissionForAFEBSGResponse xmlns="urn:bcpcorp.net/ws/bsgFacets/FacetsBillingService">
         <createBillingSubmissionForAFEBSGResult>
            <status>0</status>
            <outputMessage />
            <statusElement />
            <claimID>18E002021300</claimID>
            <claimStatus>01</claimStatus>
            <claimStatusReason>AGFP</claimStatusReason>
            <totalChargeValue>35.0000</totalChargeValue>
            <totalPayableValue>0.0000</totalPayableValue>
            <paitentPaidvalue>17.5</paitentPaidvalue>
            <totalDebitAmount>0</totalDebitAmount>
            <proceduresList>
               <MedicalProcedureOutput>
                  <ipcdId>011801</ipcdId>
                  <otherdisallowedAmountResponsibility>N</otherdisallowedAmountResponsibility>
               </MedicalProcedureOutput>
            </proceduresList>
         </createBillingSubmissionForAFEBSGResult>
      </createBillingSubmissionForAFEBSGResponse>
   </soap:Body>
</soap:Envelope>

I would expect to be getting the value '011801'. 我希望得到的值是'011801'。 Please note that multiple <MedicalProcedureOutput> nodes may occur, and they would be organized as follows: 请注意,可能会出现多个<MedicalProcedureOutput>节点,它们的组织方式如下:


               <MedicalProcedureOutput>
                  <ipcdId>725013</ipcdId>     
          <otherdisallowedAmountResponsibility>N</otherdisallowedAmountResponsibility>
               </MedicalProcedureOutput>

               <MedicalProcedureOutput>
                  <ipcdId>725105</ipcdId>   
            <otherdisallowedAmountResponsibility>N</otherdisallowedAmountResponsibility>
               </MedicalProcedureOutput>

You need to declare a default namespace for everything from within the body, since createBillingSubmissionForAFEBSGResponse has its own xmlns unnamed (therefore default) declaration which applies from that node onwards; 您需要为主体中的所有内容声明默认名称空间,因为createBillingSubmissionForAFEBSGResponse具有自己的未命名的xmlns (因此为默认)声明,该声明从该节点开始使用; so: 所以:

SELECT a.id,
  t1.icpcID FROM
  GH.WS_LOG a,
  xmltable(
  xmlnamespaces(
default 'urn:bcpcorp.net/ws/bsgFacets/FacetsBillingService',
'http://schemas.xmlsoap.org/soap/envelope/' as "soap",
'http://www.w3.org/2001/XMLSchema' as "xsd",
'http://www.w3.org/2001/XMLSchema-instance' as "xsi"
),
'/soap:Envelope/soap:Body/createBillingSubmissionForAFEBSGResponse/createBillingSubmissionForAFEBSGResult/proceduresList/MedicalProcedureOutput' passing xmltype(a.response) columns
icpcID varchar2(50) path 'ipcdId') t1
/

        ID ICPCID
---------- --------------------------------------------------
         1 011801

or with multiple nodes as you showed later int he question this will return: 或如您稍后显示的那样具有多个节点,他质疑这将返回:

        ID ICPCID
---------- --------------------------------------------------
         2 725013
         2 725105

db<>fiddle 分贝<>小提琴

您应该使用EXTRACTVALUE函数来解决它, 在这里您可以找到有关它的一些信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM