Oracle
 sql >> Base de Dados >  >> RDS >> Oracle

Como obter o valor fictício para a tag vazia XML na tabela usando o Oracle?


left join ... on 1=1
select  a.test 

from                demotable b 

        left join   XMLTable
                    (
                        '//test' 
                        passing xmltype(b.xmlTagColumn) 
                        columns 
                            test varchar(10) path '.'
                    ) a 

        on         1=1
;        

Demonstração
create table demotable (id int,xmlTagColumn varchar2(100));

insert into demotable (id,xmlTagColumn) values (1,'<X><test>123</test></X>');
insert into demotable (id,xmlTagColumn) values (2,'<Y><test>456</test></Y>');
insert into demotable (id,xmlTagColumn) values (3,'<Z><prod>123</prod></Z>');
select  b.id
       ,a.test 

from                demotable b 

        left join   XMLTable
                    (
                        '//test' 
                        passing xmltype(b.xmlTagColumn) 
                        columns 
                            test varchar(10) path '.'
                    ) a 

        on         1=1
;        
+----+--------+
| ID | TEST   |
+----+--------+
| 1  | 123    |
+----+--------+
| 2  | 456    |
+----+--------+
| 3  | (null) |
+----+--------+