我有数据库表,其中一列包含xml代码。我可以从xml元素中提取信息吗? 假设我的所有行中都有类似的内容(在1列中)。
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
我可以从所有行中提取'from'元素吗?
答案 0 :(得分:2)
您可以将列转换为XML类型(如果它没有像那样存储),然后使用xpath
来提取值:
SELECT (XPATH('/note/from/text()', my_column::xml))[1]
FROM my_table