首页 > 代码库 > xquery又xpath用法

xquery又xpath用法

DECLARE @x XML
SET @x=‘
<root>
<rogue id="001">
<hobo id="1">
<name>彪</name>
<nickname>阿彪</nickname>
<type>流氓</type>
<name>含</name>
</hobo>
</rogue>
<rogue id="002">
<hobo id="2">
<name>光辉</name>
<nickname>二辉</nickname>
<type>流氓</type>
</hobo>
</rogue>
<rogue id="001">
<hobo id="3">
<name>小德</name>
<nickname>小D</nickname>
<type>臭流氓</type>
</hobo>
</rogue>
</root>‘

--nodes (XQuery) as Table(Column) 将一个 XQuery 表达式拆分成多行

SELECT T.c.query(‘.‘) AS result
FROM @x.nodes(‘/root/rogue‘) T(c);

select T.c.value(‘(hobo/name)[1]‘,‘varchar(10)‘) AS name
FROM @x.nodes(‘/root/rogue‘) T(c);


DECLARE @xml XML=N‘
<a/>
<b>b<c>c</c></b>‘;
SELECT @xml.value(‘(/b)[1]‘, ‘varchar(10)‘), @xml.value(‘(/b/text())[1]‘, ‘varchar(10)‘)

xquery又xpath用法