久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

查詢 xml 數據 - 來自 Microsoft 的示例數據不起作用

Query xml data - sample data from Microsoft not working(查詢 xml 數據 - 來自 Microsoft 的示例數據不起作用)
本文介紹了查詢 xml 數據 - 來自 Microsoft 的示例數據不起作用的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在尋找一種無需手動編輯文件或復制粘貼內容的解決方案.我正在嘗試使用此方法來查詢 xml 文檔

聲明@myDoc xml聲明 @ProdID intSET @myDoc = '<ProductDescription ProductID="1";ProductName=公路自行車"><特點><保修>1 年部件和人工</保修><維護>提供 3 年部件和人工延長維護</Maintenance></功能></產品描述></Root>'SET @ProdID = @myDoc.value('(/Root/ProductDescription/@ProductID)[1]', 'int' )選擇@ProdID

示例來自 https://docs.microsoft.com/en-us/sql/t-sql/xml/value-method-xml-data-type?view=sql-server-ver15#a-using-the-value-method-against-an-xml-type-variable

但是當我嘗試使用此示例數據時,當我想設置變量時它不起作用.我的 xml 文件還包含單引號,這就是我選擇此示例的原因.

聲明@myDoc xml聲明 @ProdID intSET @myDoc = '<目錄><book id="bk101"><author>Gambardella, Matthew</author><title>XML 開發人員指南</title><genre>計算機</genre><價格>44.95</價格><publish_date>2000-10-01</publish_date><description>深入了解創建應用程序</description><book id="bk102"><author>Ralls, Kim</author><title>午夜雨</title><genre>幻想</genre><價格>5.95</價格><publish_date>2000-12-16</publish_date><描述>一位前建筑師與企業僵尸作斗爭,一個邪惡的女巫,和她自己成為女王的童年</description></目錄>'

來自 https 的示例數據://docs.microsoft.com/en-us/previous-versions/windows/desktop/ms762271(v=vs.85)

解決方案

您選擇的示例數據包含引用 '.

<代碼>...<title>XML 開發人員指南</title>...

這打破了文字字符串定義.SQL 引擎認為該字符串在 Developer 之后結束,并且不知道如何處理該字符串的其余部分,并試圖告訴您 2 個錯誤...

<塊引用>

Msg 102 Level 15 State 1 Line 6
's' 附近的語法不正確.

<塊引用>

Msg 105 Level 15 State 1 Line 23
字符串 ' ' 后的非封閉引號.

您可以通過轉義"解決此問題單引號和另一個引號如下:

<代碼>...<title>XML 開發人員指南</title>...

小提琴

I am looking for a solution where I do not need to edit the file, or the copy pasted content manually. I am trying to use this method to query a xml document

DECLARE @myDoc xml  
DECLARE @ProdID int  
SET @myDoc = '<Root>  
<ProductDescription ProductID="1" ProductName="Road Bike">  
<Features>  
  <Warranty>1 year parts and labor</Warranty>  
  <Maintenance>3 year parts and labor extended maintenance is available</Maintenance>  
</Features>  
</ProductDescription>  
</Root>'  
  
SET @ProdID =  @myDoc.value('(/Root/ProductDescription/@ProductID)[1]', 'int' )  
SELECT @ProdID

Example from https://docs.microsoft.com/en-us/sql/t-sql/xml/value-method-xml-data-type?view=sql-server-ver15#a-using-the-value-method-against-an-xml-type-variable

But when I try to use this sample data it will not work when I want to set the variable. My xml files also include single quotes that is why I choose this example.

DECLARE @myDoc xml  
DECLARE @ProdID int  
SET @myDoc = '<catalog>
   <book id="bk101">
      <author>Gambardella, Matthew</author>
      <title>XML Developer's Guide</title>
      <genre>Computer</genre>
      <price>44.95</price>
      <publish_date>2000-10-01</publish_date>
      <description>An in-depth look at creating applications 
      with XML.</description>
   </book>
   <book id="bk102">
      <author>Ralls, Kim</author>
      <title>Midnight Rain</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2000-12-16</publish_date>
      <description>A former architect battles corporate zombies, 
      an evil sorceress, and her own childhood to become queen 
      of the world.</description>
   </book>
</catalog>'  

Sample data from https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ms762271(v=vs.85)

解決方案

The sample data you have selected contains a quote '.

...
<title>XML Developer's Guide</title>
...

This breaks the literal string definition. The SQL engine thinks that the string ends after Developer and does not know what to do with the rest of that string and tries to tell you with 2 errors...

Msg 102 Level 15 State 1 Line 6
Incorrect syntax near 's'.

Msg 105 Level 15 State 1 Line 23
Unclosed quotation mark after the character string ' '.

You can fix this by "escaping" the single quote with another quote like so:

...
<title>XML Developer''s Guide</title>
...

Fiddle

這篇關于查詢 xml 數據 - 來自 Microsoft 的示例數據不起作用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Modify Existing decimal places info(修改現有小數位信息)
The correlation name #39;CONVERT#39; is specified multiple times(多次指定相關名稱“CONVERT)
T-SQL left join not returning null columns(T-SQL 左連接不返回空列)
remove duplicates from comma or pipeline operator string(從逗號或管道運算符字符串中刪除重復項)
Change an iterative query to a relational set-based query(將迭代查詢更改為基于關系集的查詢)
concatenate a zero onto sql server select value shows 4 digits still and not 5(將零連接到 sql server 選擇值仍然顯示 4 位而不是 5)
主站蜘蛛池模板: 国产精品国产a级 | 中文字幕免费观看 | 欧美精品在线免费观看 | 免费爱爱视频 | 91精品国产91久久久久久吃药 | 国产中文在线 | 国产美女黄色片 | 亚洲天堂一区 | 亚洲综合国产 | 日本成人区 | 日韩免费视频一区二区 | 97精品超碰一区二区三区 | 刘亦菲国产毛片bd | 一级美国黄色片 | 日本不卡在线观看 | 中文字幕在线视频免费观看 | 欧美综合国产精品久久丁香 | 亚洲精品电影网在线观看 | 亚洲高清在线观看 | 精品在线 | 精品一区二区免费视频 | 国产你懂的在线观看 | 91免费看片神器 | 日韩在线不卡 | 欧美久久久久久 | 91免费入口| 国产美女在线观看 | 色姑娘综合网 | 日本激情视频中文字幕 | 国产91丝袜在线18 | 巨大荫蒂视频欧美另类大 | 97色在线视频| 亚洲精品成人av久久 | 欧美高清成人 | 日本一区视频在线观看 | 中文字幕在线看人 | 亚洲乱码一区二区三区在线观看 | 亚洲黄色高清视频 | 成人一区二区在线 | 国产精品二区三区在线观看 | 在线一区二区三区 |