使用Oracle 12c
这看起来很简单,但我必须对如何从xml字符串中获取一个简单元素有一个心理障碍。以下产生一个空值而不是2017年。我尝试了许多不同的方法,但希望坚持使用xmlQuery而不是Extract。不确定是否需要for,但这至少可以编译并产生一些结果。对我做错了什么的想法?
with stuff AS (Select xmltype('<singleStreamlinedApplication xmlns:ns1="http://www.YYYYY.org/SSA/Person" xmlns="http://www.YYYYY.org/SSA/Person">
<ns1:schemaVersion>2.16</ns1:schemaVersion>
<ns1:changeSource>VVVVVV</ns1:changeSource>
<ns1:cbmsApplicationId>333333</ns1:cbmsApplicationId>
<ns1:cbmsCaseId>2222222</ns1:cbmsCaseId>
<ns1:cbmsAuthorizationId>11111111</ns1:cbmsAuthorizationId>
<ns1:applicationDate>2012-09-03</ns1:applicationDate>
<ns1:cbmsUpdateTimestamp>2017-04-02T20:21:34.000Z</ns1:cbmsUpdateTimestamp>
<ns1:eligibilityDeterminationDate>2017-04-02</ns1:eligibilityDeterminationDate>
<ns1:eligibilityPurpose>QUALIFIED_LIFE_CHANGE_EVENT</ns1:eligibilityPurpose>
<ns1:applicationCoverageYear>2017</ns1:applicationCoverageYear>
<ns1:peakAccountId>5555555</ns1:peakAccountId>
<ns1:applyingForWho>CONTACT_NAME_AND_OTHER_FAMILY_MEMBERS</ns1:applyingForWho>
<ns1:applyingForFinancialAssistanceIndicator>true</ns1:applyingForFinancialAssistanceIndicator>
<ns1:agreement>
<ns1:noHouseholdMemberIncarceratedIndicator>true</ns1:noHouseholdMemberIncarceratedIndicator>
<ns1:dontRenewEligibilityForFinancialBenefitsIndicator>true</ns1:dontRenewEligibilityForFinancialBenefitsIndicator>
<ns1:electronicSignatureIndicator>true</ns1:electronicSignatureIndicator>
</ns1:agreement>
<ns1:taxHousehold>
<ns1:cbmsTaxHouseholdId>999999</ns1:cbmsTaxHouseholdId>
<ns1:cbmsMagiIncomeAmount>0.0</ns1:cbmsMagiIncomeAmount>
<ns1:cbmsFederalPovertyLevel>0</ns1:cbmsFederalPovertyLevel>
<ns1:householdMember>
<ns1:cbmsPersonId>8888888</ns1:cbmsPersonId>
<ns1:name>
<ns1:firstName>XXXXX</ns1:firstName>
<ns1:lastName>YYYYY</ns1:lastName>
</ns1:name>
<ns1:dateOfBirth>1900-10-06</ns1:dateOfBirth>
<ns1:householdContactIndicator>false</ns1:householdContactIndicator>
<ns1:applyingForCoverageIndicator>true</ns1:applyingForCoverageIndicator>
<ns1:relationshipTypeToHouseholdContact>SON_OR_DAUGHTER</ns1:relationshipTypeToHouseholdContact>
<ns1:livesWithHouseholdContactIndicator>true</ns1:livesWithHouseholdContactIndicator>
<ns1:planToFileFTRIndicator>false</ns1:planToFileFTRIndicator>
<ns1:claimedAsDependantOnFTRIndicator>false</ns1:claimedAsDependantOnFTRIndicator>
<ns1:claimedAsDependantOnSomeoneElsesFTRIndicator>false</ns1:claimedAsDependantOnSomeoneElsesFTRIndicator>
<ns1:gender>FEMALE</ns1:gender>
<ns1:parentCaretakerIndicator>true</ns1:parentCaretakerIndicator>
<ns1:disabledIndicator>false</ns1:disabledIndicator>
<ns1:lifeChangeEvent>
<ns1:lifeStatusChangeReportingDate>2017-04-02</ns1:lifeStatusChangeReportingDate>
<ns1:lifeStatusEventDate>2017-04-02</ns1:lifeStatusEventDate>
<ns1:qualifiedLifeChangeEvent>CHANGE_OF_INCOME</ns1:qualifiedLifeChangeEvent>
</ns1:lifeChangeEvent>
</ns1:householdMember>
</ns1:taxHousehold>
</singleStreamlinedApplication>')
xmlcol from dual
)
Select xmlquery('xquery version "1.0";
declare namespace ns1="http://www.YYYYY.org/SSA/Person";
for $i in /singleStreamlinedApplicationRequest
return $i/ns1:applicationCoverageYear' PASSING stuff.xmlcol RETURNING CONTENT) plan_year
from stuff
答案 0 :(得分:0)
Select xmlquery('xquery version "1.0";
declare default element namespace "http://www.YYYYY.org/SSA/Person";
declare namespace ns1="http://www.YYYYY.org/SSA/Person";
for $i in /singleStreamlinedApplication
return $i/ns1:applicationCoverageYear'
PASSING stuff.xmlcol RETURNING CONTENT) plan_year
from stuff
Root元素是singleStreamlinedApplication,这个元素位于命名空间xmlns =&#34; http://www.YYYYY.org/SSA/Person"。如果你不包含声明默认元素命名空间oracle尝试从defult命名空间获取此元素。