復制代碼 代碼如下:
/*01.
02.sql xml 入門:
03. --by jinjazz
04. --
05.
06. 1、xml: 能認識元素、屬性和值
07.
08. 2、xpath: 尋址語言,類似windows目錄的查找(沒用過dir命令的話就去面壁)
09.
10. 語法格式,這些語法可以組合為條件:
11. "."表示自己,".."表示父親,"/"表示兒子,"http://"表示后代,
12. "name"表示按名字查找,"@name"表示按屬性查找
13.
14. "集合[條件]" 表示根據條件取集合的子集,條件可以是
15. 數 值:數字,last(),last()-數字 等
16. 布爾值:position()<數字,@name='條件',name='條件'
17. 條件是布爾值的時候可以合并計算:and or
18.
19. 3、xquery: 基于xpath標的準查詢語言,sqlserver xquery包含如下函數
20. exist(xpath條件):返回布爾值表示節點是否存在
21. query(xpath條件):返回由符合條件的節點組成的新的xml文檔
22. value(xpath條件,數據類型):返回指定的標量值,xpath條件結果必須唯一
23. nodes(xpath條件): 返回由符合條件的節點組成的一行一列的結果表
24.*/
復制代碼 代碼如下:
declare @data xml
set @data='
<bookstore>
<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="CHILDREN">
<title lang="jp">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="WEB">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
<book category="WEB">
<title lang="cn">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
新聞熱點
疑難解答