Oracle 10g: Extract data (select) from XML (CLOB Type)

前端 未结 7 811
悲哀的现实
悲哀的现实 2021-02-07 20:05

I\'m new in Oracle and I\'ve - maybe trivial - a problem in a select. (I\'m using Oracle 10g Express Edition).

I\'ve a DB with a field CLOB: mytab.xml This column have a

相关标签:
7条回答
  • 2021-02-07 20:08

    In case of :

    <?xml version="1.0" encoding="iso-8859-1"?>
    <info xmlns="http://namespaces.default" xmlns:ns2="http://namespaces.ns2" >
        <id> 954 </id>
        <idboss> 954 </idboss>
        <name> Fausto </name>
        <sorname> Anonimo </sorname>
        <phone> 040000000 </phone>
        <fax> 040000001 </fax>
    </info>
    

    Query :

    Select *
    from xmltable(xmlnamespaces(default 'http://namespaces.default'
                                  'http://namespaces.ns2' as "ns",
                           ), 
                    '/info'
                    passing xmltype.createxml(xml) 
                    columns id varchar2(10) path '/id',
                            idboss varchar2(500) path '/idboss',
                            etc....
    
                    ) nice_xml_table
    
    0 讨论(0)
  • 2021-02-07 20:09

    Try using xmltype.createxml(xml).

    As in,

    select extract(xmltype.createxml(xml), '//fax').getStringVal() from mytab;
    

    It worked for me.

    If you want to improve or manipulate even further.

    Try something like this.

    Select *
    from xmltable(xmlnamespaces('some-name-space' as "ns", 
                                      'another-name-space' as "ns1",
                               ), 
                        '/ns/ns1/foo/bar'
                        passing xmltype.createxml(xml) 
                        columns id varchar2(10) path '//ns//ns1/id',
                                idboss varchar2(500) path '//ns0//ns1/idboss',
                                etc....
    
                        ) nice_xml_table
    

    Hope it helps someone.

    0 讨论(0)
  • 2021-02-07 20:15

    In case the XML store in the CLOB field in the database table. E.g for this XML:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Awmds>
        <General_segment>
            <General_segment_id>
            <Customs_office_code>000</Customs_office_code>
        </General_segment_id>
    </General_segment>
    </Awmds>
    

    This is the Extract Query:

    SELECT EXTRACTVALUE (
        xmltype (T.CLOB_COLUMN_NAME),
        '/Awmds/General_segment/General_segment_id/Customs_office_code')
        AS Customs_office_code
    FROM TABLE_NAME t;
    
    0 讨论(0)
  • 2021-02-07 20:17

    this query runs perfectly in my case

    select xmltype(t.axi_content).extract('//Lexis-NexisFlag/text()').getStringVal() from ax_bib_entity t
    
    0 讨论(0)
  • 2021-02-07 20:27

    Try this instead:

    select xmltype(t.xml).extract('//fax/text()').getStringVal() from mytab t
    
    0 讨论(0)
  • 2021-02-07 20:27

    You can achieve with below queries

    1. select extract(xmltype(xml), '//fax/text()').getStringVal() from mytab;

    2. select extractvalue(xmltype(xml), '//fax') from mytab;

    0 讨论(0)
提交回复
热议问题