我是oracle的新手,我在表格中有XML列,其中列数据是XML格式
即,
<?xml version="1.0" encoding="UTF-8"?>
<charge textid="dacebab6-962e-3-b23d70eef85a" id="parse"><properties/></charge>
现在我只想获得 textid ,所以如何通过 SQL 查询获得textid。
我尝试从emp_datails中选择XMLSequence(Extract(x,&#39; / charge / textid / text()&#39;)); 但无效。
答案 0 :(得分:1)
使用EXTRACTVALUE。
select EXTRACTVALUE(x,'/charge/@textid') from emp_datails;
示例:
WITH x(y) AS
(SELECT xmltype('<?xml version="1.0" encoding="UTF-8"?>
<charge textid="dacebab6-962e-3-b23d70eef85a" id="parse">asdd<properties/>asd</charge>')
FROM dual
)
SELECT EXTRACTVALUE(y, '/charge/@textid') textid FROM x;
TEXTID
----------
dacebab6-962e-3-b23d70eef85a
答案 1 :(得分:0)
使用此语句,您可以提取textid:
-- Your data
with data as
(select '<?xml version="1.0" encoding="UTF-8"?>
<charge textid="dacebab6-962e-3-b23d70eef85a" id="parse"><properties/></charge>' as xmlval
from dual)
(SELECT attr_value
FROM data d,
xmltable('.' PASSING xmltype(d.xmlval) COLUMNS attr_value
VARCHAR2(30) PATH '/charge/@textid'));