久久久久久久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)
主站蜘蛛池模板: 黄色大片在线播放 | 国产成人精品一区二 | 看片wwwwwwwwwww | 国产精品婷婷 | 欧美精品久久久久久久久老牛影院 | 免费看a| 国产视频精品区 | 在线观看视频福利 | 日本韩国欧美在线观看 | 最近中文字幕免费 | 国产成人啪免费观看软件 | 国产一区视频在线 | 中文字幕av在线播放 | 91精品国产乱码久久久久久久久 | 国产一级免费视频 | 99这里只有精品 | 精品国模一区二区三区欧美 | 中文字幕高清 | 欧美激情国产日韩精品一区18 | 国产高潮好爽受不了了夜夜做 | 国产黄色大片 | 成人免费视频网站在线看 | 欧美精品久久久久 | 最新中文字幕在线 | 国产精品久久国产精品99 gif | 一级欧美黄色片 | 国产精品久久久久久一区二区三区 | 久久看精品| 久久久亚洲一区 | 久在线精品视频 | 国产成人免费视频网站视频社区 | 久久99久久99精品免视看婷婷 | 精品欧美一区二区在线观看 | 久久99精品久久久久久国产越南 | 成人三级影院 | 一级黄色毛片免费 | 国产一二三视频在线观看 | 色综合中文| 日韩精品在线一区二区 | 黄色大全免费看 | 激情 一区 |