Monday, 15 June 2015

oracle11g - How to extract text including spaces in XMLTYPE oracle -



oracle11g - How to extract text including spaces in XMLTYPE oracle -

when using next query,

select xmlcast(xmlquery('/books/book' passing xmlcolumn returning content) clob) "book" samplexml;

against xml below,

<books> <book> <title>basics</title> <price>10</price> </book> </books>

i expect info returned as,

basics 10 , due space between title tag , cost tag, instead getting basics10

edit : this example, there may number of tags within them. want spaces included if between 2 tags

try this

select x.title || ' ' || x.price samplexml s, xmltable('/books/book' passing xmltype('<books><book> <title>basics</title> <price>10</price> </book></books>') columns title varchar2(150) path '/*/./title', cost varchar2(1000) path '/*/price') x

into xmltible set name of column samplexml table, e.g. if column named xdata transform such

select x.title || ' ' || x.price samplexml s, xmltable('/books/book' passing xmltype(s.xdata) columns title varchar2(150) path '/*/./title', cost varchar2(1000) path '/*/price') x

oracle oracle11g xquery xmltype

No comments:

Post a Comment