sql—在未定义命名空间的情况下从oracle中的xml中提取值

dwbf0jvd  于 2021-08-09  发布在  Java
关注(0)|答案(0)|浏览(210)

我试图从oracle数据库中的clob字段中提取值。我在下面列出了clob字段示例数据。据我所知,clob并不声明名称空间。当我在传递中包含整个clob时,我能够得到要返回的值,但当我只引用包含clob的字段时,就不能。除此之外没有其他区别,我无法理解为什么一个返回值而另一个不返回。
clob样本:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><ResponseEx xmlns="urn:lnrisk:ws:testing:ruleplan@ver=1">
 <Response> 
 <Messages>
 <Message>
 <Type>G</Type>
 <Code>C6</Code>
 <Message>No Data Found.
 </Message>
 </Message>
 <Message>
 <Type>G</Type>
 <Message>ORDER NUMBER: AQF6LSL
 </Message>
 </Message>
 </Messages>
 <RequesterInformation>
 <Name>BIGBOB</Name>
 <AccountNumber>1111ABC</AccountNumber>
 </RequesterInformation>
 <TransactionDetailsEx>
 <TransactionDetails>
 <RuleplanId>111112</RuleplanId>
 <DateTimeReceived>
 <Year>2020</Year>
 <Month>5</Month>
 <Day>19</Day>
 <Hour24>12</Hour24>
 <Minute>58</Minute>
 <Second>17</Second>
 <MilliSeconds>317</MilliSeconds>
 </DateTimeReceived>
 <DateTimeCompleted>
 <Year>2020</Year>
 <Month>5</Month>
 <Day>19</Day>
 <Hour24>12</Hour24>
 <Minute>58</Minute>
 <Second>17</Second>
 <MilliSeconds>563</MilliSeconds>
 </DateTimeCompleted>
 <QuoteBacks/>
 </TransactionDetails>
 <ProcessingStatus>Complete with Errors</ProcessingStatus>
 <TransactionId>ABC895CL</TransactionId>
 </TransactionDetailsEx>
 <SearchBy>
 <Subjects/>
 <Vehicles>
 <InquiryVehicle vehicleId="VEH1">
 <PlateNumber>EEEE44444</PlateNumber>
 <PlateState>AB</PlateState>
 </InquiryVehicle></Vehicles>
 </SearchBy><Products>
 <ClaimsDataFill>
 <InquiryClaimsDataFill>
 <CarrierName>BIGBOB</CarrierName>
 <CarrierPolicyNumber>9999999999</CarrierPolicyNumber>
 <ClaimNumber>cc:98486965</ClaimNumber>
 <ClaimState>CA</ClaimState>
 <ParticipantNumber>001</ParticipantNumber>
 <DateofLoss><Year>2020</Year>
 <Month>5</Month>
 <Day>19</Day>
 </DateofLoss>
 <ParticipantType>Claimant</ParticipantType>
 <ParticipantRole>Owner</ParticipantRole>
 <SearchBy>
 <Vehicles>
 <Vehicle ref="VEH1">VEH1</Vehicle>
 </Vehicles>
 </SearchBy>
 </InquiryClaimsDataFill>
 </ClaimsDataFill>
 </Products>
 <ProductResults>
 <ClaimsDataFillResults/>
 </ProductResults>
 </Response>
 </ResponseEx>

此代码不会产生以下结果:

SELECT 
stbl.EXT_TRANSACTIONIDTXT,  
stbl.EXT_RESPONSETEXT, 
xt.* 
FROM sample_table stbl, 
    xmltable( xmlnamespaces( default 'urn:lnrisk:ws:testing:ruleplan@ver=1'), 
    '/ResponseEx/Response/TransactionDetailsEx/TransactionDetails'
    PASSING XMLTYPE(stbl.EXT_RESPONSETEXT)
        COLUMNS 
            Year  PATH 'DateTimeReceived/Year',
            Month  PATH 'DateTimeReceived/Month'
            )xt;

虽然此代码确实会产生结果:

SELECT 
stbl.EXT_TRANSACTIONIDTXT,  
stbl.EXT_RESPONSETEXT, 
xt.* 
FROM
sample_table stbl,
xmltable(xmlnamespaces( default 'urn:lnrisk:ws:testing:ruleplan@ver=1'), '/ResponseEx/Response/TransactionDetailsEx/TransactionDetails'
    PASSING XMLTYPE('<?xml version="1.0" encoding="UTF-8" standalone="yes"?><ResponseEx xmlns="urn:lnrisk:ws:testing:ruleplan@ver=1">
 <Response> 
 <Messages>
 <Message>
 <Type>G</Type>
 <Code>C6</Code>
 <Message>No Data Found.
 </Message>
 </Message>
 <Message>
 <Type>G</Type>
 <Message>ORDER NUMBER: AQF6LSL
 </Message>
 </Message>
 </Messages>
 <RequesterInformation>
 <Name>BIGBOB</Name>
 <AccountNumber>1111ABC</AccountNumber>
 </RequesterInformation>
 <TransactionDetailsEx>
 <TransactionDetails>
 <RuleplanId>111112</RuleplanId>
 <DateTimeReceived>
 <Year>2020</Year>
 <Month>5</Month>
 <Day>19</Day>
 <Hour24>12</Hour24>
 <Minute>58</Minute>
 <Second>17</Second>
 <MilliSeconds>317</MilliSeconds>
 </DateTimeReceived>
 <DateTimeCompleted>
 <Year>2020</Year>
 <Month>5</Month>
 <Day>19</Day>
 <Hour24>12</Hour24>
 <Minute>58</Minute>
 <Second>17</Second>
 <MilliSeconds>563</MilliSeconds>
 </DateTimeCompleted>
 <QuoteBacks/>
 </TransactionDetails>
 <ProcessingStatus>Complete with Errors</ProcessingStatus>
 <TransactionId>ABC895CL</TransactionId>
 </TransactionDetailsEx>
 <SearchBy>
 <Subjects/>
 <Vehicles>
 <InquiryVehicle vehicleId="VEH1">
 <PlateNumber>EEEE44444</PlateNumber>
 <PlateState>AB</PlateState>
 </InquiryVehicle></Vehicles>
 </SearchBy><Products>
 <ClaimsDataFill>
 <InquiryClaimsDataFill>
 <CarrierName>BIGBOB</CarrierName>
 <CarrierPolicyNumber>9999999999</CarrierPolicyNumber>
 <ClaimNumber>cc:98486965</ClaimNumber>
 <ClaimState>CA</ClaimState>
 <ParticipantNumber>001</ParticipantNumber>
 <DateofLoss><Year>2020</Year>
 <Month>5</Month>
 <Day>19</Day>
 </DateofLoss>
 <ParticipantType>Claimant</ParticipantType>
 <ParticipantRole>Owner</ParticipantRole>
 <SearchBy>
 <Vehicles>
 <Vehicle ref="VEH1">VEH1</Vehicle>
 </Vehicles>
 </SearchBy>
 </InquiryClaimsDataFill>
 </ClaimsDataFill>
 </Products>
 <ProductResults>
 <ClaimsDataFillResults/>
 </ProductResults>
 </Response>
 </ResponseEx>')
        COLUMNS 
            Year  PATH 'DateTimeReceived/Year',
            Month  PATH 'DateTimeReceived/Month'
            )xt;

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题