Oracle CLOB中的ExtractValue返回null

时间:2015-03-20 12:02:41

标签: xml oracle extract clob

我是XML和Clobs的新手。我已经阅读了很多关于这个主题的帖子。我试图从这个clob中提取studentID值。我正在使用Oracle 11.2

<OcXml xmlns="http://oc.csr.com/xml">
  <OcSharedXml>
    <Templates>
      <Template ns:TemplateId="130" ns:TemplateName="Student Graduation Fees" ns:TemplateFilename="Student_Graduation_Fees_1.doc" ns:TemplateSequence="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns="http://oc.rsi.com/xml">
        <Sections>
          <Section ns:SectionId="146" ns:SectionName="Main" ns:SectionSequence="1" ns:MaxRepeat="1">
            <Elements>
              <Element ns:ElementId="134" ns:ElementName="CurrentDt" ns:FieldName="DateOfNotice" ns:DefaultValue="" ns:Editable="false" ns:ElementSequence="1" ns:ElementType="ElmProc" ns:Mandatory="false" ns:Shared="true" ns:DataType="String" ns:Format="NoFmt" ns:RecipientId="" ns:Multiline="false" ns:RecipientAddressFlag="false">
                <ElementValue>2/19/2015</ElementValue>
              </Element>
              <Element ns:ElementId="24" ns:ElementName="InvoiceNo" ns:FieldName="InvoiceNo" ns:DefaultValue="" ns:Editable="true" ns:ElementSequence="2" ns:ElementType="ElmProc" ns:Mandatory="false" ns:Shared="true" ns:DataType="String" ns:Format="NoFmt" ns:RecipientId="" ns:Multiline="false" ns:RecipientAddressFlag="false">
                <ElementValue>352</ElementValue>
              </Element>
              <Element ns:ElementId="16" ns:ElementName="StudentID" ns:FieldName="StudentID" ns:DefaultValue="" ns:Editable="true" ns:ElementSequence="3" ns:ElementType="ElmProc" ns:Mandatory="false" ns:Shared="true" ns:DataType="String" ns:Format="NoFmt" ns:RecipientId="" ns:Multiline="false" ns:RecipientAddressFlag="false">
                <ElementValue>557481300</ElementValue>
              </Element>
              <Element ns:ElementId="43" ns:ElementName="DegreeType" ns:FieldName="DegreeType" ns:DefaultValue="" ns:Editable="false" ns:ElementSequence="4" ns:ElementType="ElmProc" ns:Mandatory="false" ns:Shared="true" ns:DataType="String" ns:Format="NoFmt" ns:RecipientId="" ns:Multiline="false" ns:RecipientAddressFlag="false">
                <ElementValue>BS</ElementValue>
              </Element>
              <Element ns:ElementId="44" ns:ElementName="GraduationYear" ns:FieldName="GraduationYear" ns:DefaultValue="" ns:Editable="false" ns:ElementSequence="5" ns:ElementType="ElmProc" ns:Mandatory="false" ns:Shared="true" ns:DataType="String" ns:Format="NoFmt" ns:RecipientId="" ns:Multiline="false" ns:RecipientAddressFlag="false">
                <ElementValue>2015</ElementValue>
              </Element>
            </Elements>
          </Section>
        </Sections>
      </Template>
    </Templates>
  </OcSharedXml>
</OcXml>

这是我的选择声明。它返回空值

SELECT EXTRACTVALUE(xmltype(clob_column),&#39; / Templates / Template / Sections / Elements / Element [@ElementName =&#34; StudentID&#34;]&#39;) 来自student_table;

谢谢!

1 个答案:

答案 0 :(得分:4)

您没有给出路径中的所有节点 - 您缺少OcXml,OcSharedXml和Section以及ElementValue - 但您还需要提供命名空间信息,因为您要查找的属性称为{{ 1}}:

ns:ElementName

或简化/通配路径:

SELECT EXTRACTVALUE(xmltype(clob_column),
  '/OcXml/OcSharedXml/Templates/Template/Sections/Section/Elements/Element[@ns:ElementName="StudentID"]/ElementValue',
  'xmlns="http://oc.csr.com/xml" xmlns:ns="http://oc.rsi.com/xml"')
FROM student_table;

EXTRACTVALUE(XMLTYPE(CLOB_COLUMN),'/OCXML/OCSHAREDXML/TEMPLATES/TEMPLATE/SECTION
--------------------------------------------------------------------------------
557481300                                                                       
相关问题