1.xml.exist
輸入為XQuery表達式,返回0,1或是Null。0表示不存在,1表示存在,Null表示輸入為空
2.xml.value
輸入為XQuery表達式,返回一個SQL Server標量值
3.xml.query
輸入為XQuery表達式,返回一個SQL Server XML類型流
4.xml.nodes
輸入為XQuery表達式,返回一個XML格式文檔的一列行集
5.xml.modify
使用XQuery表達式對XML的節點進行insert , update 和 delete 操作。
下面通過例子對上面的五種操作進行說明:
declare @XMLVar xml = '
<catalog>
<book category="ITPro">
<title>Windows Step By Step</title>
<author>Bill Zack</author>
<price>49.99</price>
</book>
<book category="Developer">
<title>Developing ADO .NET</title>
<author>Andrew Brust</author>
<price>39.93</price>
</book>
<book category="ITPro">
<title>Windows Cluster Server</title>
<author>Stephen Forte</author>
<price>59.99</price>
</book>
</catalog>'
1. xml.exist
select @XMLVar.exist('/catalog/book')-----返回1
select @XMLVar.exist('/catalog/book/@category')-----返回1
select @XMLVar.exist('/catalog/book1')-----返回0
set @XMLVar = null
select @XMLVar.exist('/catalog/book')-----返回null
2.xml.value
select @XMLVar.value('/catalog[1]/book[1]','varchar(MAX)')
select @XMLVar.value('/catalog[1]/book[2]/@category','varchar(MAX)')
select @XMLVar.value('/catalog[2]/book[1]','varchar(MAX)')
結果集為:
Windows Step By StepBill Zack49.99 Developer NULL
3.xml.query
select @XMLVar.query('/catalog[1]/book')
select @XMLVar.query('/catalog[1]/book[1]')
select @XMLVar.query('/catalog[1]/book[2]/author')
結果集分別為:
<book category="ITPro">
<title>Windows Step By Step</title>
<author>Bill Zack</author>
<price>49.99</price>
</book>
<book category="Developer">
<title>Developing ADO .NET</title>
<author>Andrew Brust</author>
<price>39.93</price>
</book>
<book category="ITPro">
<title>Windows Cluster Server</title>
<author>Stephen Forte</author>
<price>59.99</price>
</book>
<book category="ITPro">
<title>Windows Step By Step</title>
<author>Bill Zack</author>
<price>49.99</price>
</book>
<author>Andrew Brust</author>
4.xml.nodes
select T.c.query('.') as result from @XMLVar.nodes('/catalog/book') as T(c)
select T.c.query('title') as result from @XMLVar.nodes('/catalog/book') as T(c)
結果集分別為:
<book category="ITPro"><title>Windows Step By Step</title><author>Bill …………
<book category="Developer"><title>Developing ADO .NET</title><author>Andrew …………
<book category="ITPro"><title>Windows Cluster Server</title><author>Stephen …………
<title>Windows Step By Step</title>
<title>Developing ADO .NET</title>
<title>Windows Cluster Server</title>
5.xml.modify
關于modify內容,請參見下一篇文章。
SQLServer XML數據的五種基本操作
2019-11-11 15:24mssql教程網 Sql Server
SQLServer XML數據的五種基本操作語句
延伸 · 閱讀
- 2022-03-09C# Ado.net實現讀取SQLServer數據庫存儲過程列表及參
- 2022-03-07C#操作XML文件步驟
- 2022-03-07Spring Xml裝配Bean的思路詳解
- 2022-03-05sqlserver數據庫加密后無法使用MDF,LDF,log文件名稱被
- 2022-03-02C#使用XmlDocument或XDocument創建xml文件
- 2022-03-02Java中String的JdbcTemplate連接SQLServer數據庫的方法
- Sql Server
SQL2005 存儲過程解密方法
SQL2005 存儲過程解密方法,需要的朋友可以參考下。...
- Sql Server
SQL_Server全文索引的用法解析
SQL Server全文索引相信大家都有一定的了解,下面就為您介紹SQL Server全文索引的用法及相關的語句,希望可以讓您對SQL Server全文索引能有更深的認識 ...
- Sql Server
深入SQLServer中ISNULL與NULLIF的使用詳解
本篇文章是對SQLServer中ISNULL與NULLIF的使用進行了詳細分析介紹,需要的朋友參考下 ...
- Sql Server
三種SQL分頁查詢的存儲過程代碼
三種SQL分頁查詢的存儲過程代碼,需要的朋友可以參考下。 ...
- Sql Server
SQLServer 數據庫的數據匯總完全解析(WITH ROLLUP)
乍一看,好像很容易,用group by好像能實現?但仔細研究下去,你又會覺得group by也是無能為力,總欠缺點什么,無從下手。那么,到底該如何做呢?別急,...
- Sql Server
SQLServer2005創建定時作業任務
這篇文章主要為大家介紹了SQLServer2005創建定時作業任務的詳細過程,具有一定的參考價值,感興趣的小伙伴們可以參考一下 ...
- Sql Server
SQL JOIN 連接詳細介紹及簡單使用實例
這篇文章主要介紹了SQL JOIN 連接詳細介紹及簡單使用實例的相關資料,需要的朋友可以參考下 ...
- Sql Server
SQLServer2005 批量查詢自定義對象腳本
SQLServer2005 批量查詢自定義對象腳本,使用系統函數object_definition和系統表 sysobjects 就可以了 ...