如何在 SQL Server 中更改 dbms_xmlgen.getxml(选择查询)
Posted
技术标签:
【中文标题】如何在 SQL Server 中更改 dbms_xmlgen.getxml(选择查询)【英文标题】:How to change dbms_xmlgen.getxml(select query) in SQL Server 【发布时间】:2021-12-27 19:57:22 【问题描述】:我们正在从 Oracle 迁移到 SQL Server。 Oracle数据库中有写dbms_xmlgen.getxml(select query)
的视图。我们如何在 SQL Server 中更改它。
请帮帮我。
【问题讨论】:
请提供一个可重现的最小示例。 【参考方案1】:SQL Server 中的相应功能是SELECT ... FOR XML 查询。来自docs的EG:
USE AdventureWorks2012;
GO
SELECT E.BusinessEntityID "@EmpID",
'Example of using node tests such as text(), comment(), processing-instruction()' as "comment()",
'Some PI' as "processing-instruction(PI)",
'Employee name and address data' as "text()",
'middle name is optional' as "EmpName/text()",
FirstName as "EmpName/First",
MiddleName as "EmpName/Middle",
LastName as "EmpName/Last",
AddressLine1 as "Address/AddrLine1",
AddressLine2 as "Address/AddrLIne2",
City as "Address/City"
FROM HumanResources.Employee AS E
INNER JOIN Person.Person AS P
ON P.BusinessEntityID = E.BusinessEntityID
INNER JOIN Person.BusinessEntityAddress AS BAE
ON BAE.BusinessEntityID = E.BusinessEntityID
INNER JOIN Person.Address AS A
ON BAE.AddressID = A.AddressID
WHERE E.BusinessEntityID=1
FOR XML PATH;
【讨论】:
以上是关于如何在 SQL Server 中更改 dbms_xmlgen.getxml(选择查询)的主要内容,如果未能解决你的问题,请参考以下文章
如何在 SQL Server 2012 中使用 html 更改表格中特定单元格的颜色?
如何在 SQL Server 中更改 dbms_xmlgen.getxml(选择查询)
如何在 SQL Server 的 Doctrine 2 中更改 DQL 查询中的 LockMode