get parent child in XMLTable in oracle

3.1k views Asked by At

I want to know if there are any way to collect the parent child tag when you are creating an XMLTable. The XML is like this:

<Data>
    <Identificacion/>
    <UOFDATA>
        <CodigoDATA v="AAAASSA"/>
        <PeriodoDATA>
            <IntervaloDATA v="2013-10-14/2013-10-18"/>
            <UPDATA>
                <CodigoDATA v="AGAGGGG"/>
                <UFDATA>
                    <CodigoDATA v="AAASSCV"/>
                    <.....

I´m listings all the '/Data/UOFDATA/PeriodoDATA', and i want to know the UOFData (the parent child. I try some ways, but always return null!

    Select intervalo, uof, uof2, uof3 from
XMLTable(
        '/Data/UOFDATA/PeriodoDATA'
        passing (select xmltype(pl_string) as xmldataselect from consultas where cdconsult = 1000)
        columns Intervalo varchar2(60) path 'IntervaloDATA/@v',
                UOF varchar2(60) path './ancestor::UOFDATA/CodigoDATA/@v',
                UOF2 xmltype path './parent::node()',
                UOF3 varchar2(60) path './../CodigoDATA/@v'
       ) tableIntervalo

Thanks in advance

1

There are 1 answers

3
mcalmeida On BEST ANSWER

Since you just have one parent node CodigoDATA but many child nodes PeriodoDATA, I suggest you split query into 2 different ones: the first would extract the parent information CodigoDATA, and the second would the PeriodoDATA child nodes (similar to what you are doing).