使用 SSIS 分解数据库中的 XML

发布于 2024-11-14 15:48:00 字数 226 浏览 4 评论 0原文

我正在寻找一种从 SQL 数据库中提取 XML 并通过 SSIS 批量分解 XML 的方法。我目前有一个包,可以从数据库中提取 XML 并通过变量将 XML 传递到存储过程以进行粉碎,但这一次只能处理 1 条记录。当处理 100,000 条记录时,这可能会变得相当耗时。

我想使用 SSIS 一次分解多个 XML 值。 SSIS 可以做到这一点吗?也许在数据流任务中,所有 XML 值都是从源中选择然后传递给某种解析器的?

I am looking for a way to pull XML from a SQL database and shred the XML via SSIS in bulk. I currently have a package that can pull XML from the database and pass the XML to a stored procedure, via variable, for shredding but this only works 1 record at a time. When processing 100,000 records, this can become quite time consuming.

I would like to shred multiple XML values at once using SSIS. Is this possible with SSIS? Perhaps something in a Data Flow Task where all the XML values are selected from a source then passed to a parser of some sort?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忆离笙 2024-11-21 15:48:00

因此,经过大量搜索和思考问题后,我重新设计了执行粉碎的存储过程。我没有分解传递到存储过程中的变量,而是直接分解 XML 列本身。这使我能够一次分解许多 XML 值,而不是一次循环将它们传递给一个存储过程。这给了我想要的性能提升。所以不是这样的......

SET @xmlData = CAST(@xmlMessageData AS XML)

SELECT
   , row.value('xmlNode1[1]', 'BIT' )                   AS Column1  
   , row.value('xmlNode2[1]', 'NVARCHAR(255)')          AS Column2
   , row.value('xmlNode3[1]', 'BIT' )                   AS Column3
   , row.value('xmlNode4[1]/Name[1]', 'NVARCHAR(255)' ) AS Column4
FROM @xmlData.nodes('xmlRootNode') AS T1(row)

我现在这样做......

SELECT
   , row.value('xmlNode1[1]', 'BIT' )                   AS Column1  
   , row.value('xmlNode2[1]', 'NVARCHAR(255)')          AS Column2
   , row.value('xmlNode3[1]', 'BIT' )                   AS Column3
   , row.value('xmlNode4[1]/Name[1]', 'NVARCHAR(255)' ) AS Column4
FROM [ESBMessagesData] D
CROSS APPLY
    [DataItem].nodes('xmlRootNode') AS T1(row)

So after a lot of searching and thinking about the problem, I redesigned the stored procedures that did the shredding. Instead of shredding a variable being passed into the stored procedure, I just shredded from the XML column itself. This allowed me to shred many XML values at once instead of looping and passing them to a stored procedure one at a time. This gave me the performance boost I was looking for. So instead of something like this...

SET @xmlData = CAST(@xmlMessageData AS XML)

SELECT
   , row.value('xmlNode1[1]', 'BIT' )                   AS Column1  
   , row.value('xmlNode2[1]', 'NVARCHAR(255)')          AS Column2
   , row.value('xmlNode3[1]', 'BIT' )                   AS Column3
   , row.value('xmlNode4[1]/Name[1]', 'NVARCHAR(255)' ) AS Column4
FROM @xmlData.nodes('xmlRootNode') AS T1(row)

I now do this...

SELECT
   , row.value('xmlNode1[1]', 'BIT' )                   AS Column1  
   , row.value('xmlNode2[1]', 'NVARCHAR(255)')          AS Column2
   , row.value('xmlNode3[1]', 'BIT' )                   AS Column3
   , row.value('xmlNode4[1]/Name[1]', 'NVARCHAR(255)' ) AS Column4
FROM [ESBMessagesData] D
CROSS APPLY
    [DataItem].nodes('xmlRootNode') AS T1(row)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文