我有SQLite 338.2列中有XML标记的表:
with cte(xml_tag) as (values
('<Event time="Sat Apr 22 1:01:51.887" type="Debug" thread="2164: Main CIM worker thread" elapsed="1" function="Geodatabase.Cursor" code="EndCursor">'),
('<Event time="Sat Apr 22 1:01:51.883" type="Debug" thread="2164: Main CIM worker thread" elapsed="23" function="Geodatabase.Cursor" code="EndCursor">'),
('<Event time="Sat Apr 22 1:01:51.874" type="Debug" thread="2164: Main CIM worker thread" elapsed="456" function="Geodatabase.Cursor" code="EndCursor">'),
('<Event time="Sat Apr 22 1:01:51.846" type="Debug" thread="2164: Main CIM worker thread" elapsed="7890" function="Geodatabase.Cursor" code="EndCursor">'))
select * from cte
db<>fiddle
我想从elapsed
标记中提取值作为数字:
elapsed
-------
1
23
456
7890
如何使用SQL查询从XML标记中提取值?
1条答案
按热度按时间a2mppw5e1#
假设所有
xml_tag
的值都包含子字符串'elapsed='
(只有一次),你可以使用字符串函数:通过将
0
添加到提取的字符串中,它被隐式地转换为一个数字。参见demo。