首先创建一个表:
CREATE TABLE [dbo].[tbDevLanguage] ([languages] xml)
把xml的数据Insert(插入)至刚才创建的表中:
DECLARE @xml XML = '
<Languages>
<language name="VB.NET"/>
<language name="C#"/>
<language name="Java" />
</Languages>
'
INSERT INTO [dbo].[tbDevLanguage] VALUES (@xml)
表中有数据了,我们就可以使用xml.values()函数演练了,现想取得xml的第二个元素/Languages[1]/language[2]:
SELECT [languages].value('/Languages[1]/language[2]/@name', 'varchar(40)') AS [language]
FROM [dbo].[tbDevLanguage]