为什么SQL Azure不支持SQL OpenXML?我们可以在SQL Azure中使用哪些替代方案?最后,在即将推出的SQL版本中是否会弃用SQL OpenXML?
答案 0 :(得分:4)
有两种选择:
1)Nodes()和Value()函数
请参阅Restrictions of Stored Procedures in SQL Azure和Value(), Nodes(), and OpenXML()。
2)XQuery
请参阅Introduction to XQuery in SQL Server 2005和SQL Server 2005 XQuery and XML-DML - Part 1。
答案 1 :(得分:2)
这一定在某些时候发生了变化。它出现在9.25.2017,openxml在SQL Azure中运行良好。我刚刚在SQL Azure DB上从https://docs.microsoft.com/en-us/sql/relational-databases/xml/examples-using-openxml运行了以下示例,它生成了显示的结果:
DECLARE @DocHandle int
DECLARE @XmlDocument nvarchar(1000)
SET @XmlDocument = N'<ROOT>
<Customer CustomerID="VINET" ContactName="Paul Henriot">
<Order OrderID="10248" CustomerID="VINET" EmployeeID="5"
OrderDate="1996-07-04T00:00:00">
<OrderDetail ProductID="11" Quantity="12"/>
<OrderDetail ProductID="42" Quantity="10"/>
</Order>
</Customer>
<Customer CustomerID="LILAS" ContactName="Carlos Gonzlez">
<Order OrderID="10283" CustomerID="LILAS" EmployeeID="3"
OrderDate="1996-08-16T00:00:00">
<OrderDetail ProductID="72" Quantity="3"/>
</Order>
</Customer>
</ROOT>'
-- Create an internal representation of the XML document.
EXEC sp_xml_preparedocument @DocHandle OUTPUT, @XmlDocument
-- Execute a SELECT statement using OPENXML rowset provider.
SELECT *
FROM OPENXML (@DocHandle, '/ROOT/Customer',1)
WITH (CustomerID varchar(10),
ContactName varchar(20))
EXEC sp_xml_removedocument @DocHandle
输出:
CustomerID ContactName
VINET Paul Henriot
LILAS Carlos Gonzlez
我没有看到此处列出的OPENXML:https://docs.microsoft.com/en-us/azure/sql-database/sql-database-transact-sql-information#transact-sql-syntax-not-supported-in-sql-database