簡體   English   中英

你如何在SQL中讀取XML文件?

[英]How do you read an XML file in SQL?

我正在使用SQL Server 2014使用xquery查詢XML文本。 我可以插入部分XML文本進行查詢,但我需要能夠指向本地文件來讀取和查詢它,並且無法弄清楚如何執行此操作。 以下是我目前正在做的事情。

declare @xmldata xml    
set @xmldata = '
<Orders>
  <Order OrderID="100" OrderDate="1/30/2012">
   <OrderDetail ProductID="1" Quantity="3">
    <Price>350</Price>
   </OrderDetail>
   <OrderDetail ProductID="2" Quantity="8">
    <Price>500</Price>
   </OrderDetail>
   <OrderDetail ProductID="3" Quantity="10">
    <Price>700</Price>
   </OrderDetail>
  </Order>
  <Order OrderID="200" OrderDate="2/15/2012">
   <OrderDetail ProductID="4" Quantity="5">
    <Price>120</Price>
   </OrderDetail>
  </Order>
 </Orders>'

SELECT  x.c.value('(OrderDetail)[2]', 'varchar(100)') as OrderDetail
FROM @xmldata.nodes('/Orders/Order') x(c)

--XMl File Location: "C:\Users\User\X\Example.xml")

提前致謝!

試試這個https://msdn.microsoft.com/en-CA/library/ms191184.aspx

INSERT INTO T(XmlCol)  
SELECT * FROM OPENROWSET(  
BULK 'c:\SampleFolder\SampleData3.txt',  
SINGLE_BLOB) AS x;  

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM