简体   繁体   English

将巨大的 XML 批量导入 SQL Cellt

[英]Bulk import of a huge XML into an SQL Cellt

I'm trying to import an XML file into a SQL cell to process it.我正在尝试将 XML 文件导入 SQL 单元格以进行处理。 My first idea is do an OPENROWSET to keep the XML and the just divide it with NODES.我的第一个想法是做一个 OPENROWSET 来保留 XML 并用 NODES 来划分它。 One of the XML its too huge to keep it on a CELL, so the OPENROWSET cut the XML, so It's impossible to work with it then.其中一个 XML 太大而无法保存在 CELL 中,因此 OPENROWSET 切断了 XML,因此无法使用它。 That is the code:那是代码:

 DECLARE @XMLwithOpenXML TABLE ( Id INT IDENTITY PRIMARY KEY, XMLData XML, LoadedDateTime DATETIME ) INSERT INTO @XMLwithOpenXML(XMLData, LoadedDateTime) SELECT CONVERT(XML, BulkColumn) AS BulkColumn ,GETDATE() FROM OPENROWSET(BULK 'C:\temp\PP015.xml', SINGLE_CLOB) AS x; SELECT * FROM @XMLwithOpenXML

The second option is use the BCP to do the same, but I'm getting an error.第二个选项是使用 BCP 来做同样的事情,但我得到了一个错误。

 DECLARE @sql NVARCHAR(500) SET @sql = 'bcp [ExternaDB].[dbo].[xmltab] IN "C:\temp\PP015.xml" -T -c' EXEC xp_cmdshell @sql select * from xmltab

在此处输入图像描述

I want to know if I'm on the correct way (How to work with an XML when is already in an SQL cell I know how to do it) and how I can BULK import the full XML into a cell without Length constraint.我想知道我的方法是否正确(当我知道如何在 SQL 单元格中使用 XML 时如何使用它)以及如何将完整的 XML 批量导入没有长度约束的单元格。

What is the size of the XML file on the file system?文件系统上 XML 文件的大小是多少?

Please try the following solution.请尝试以下解决方案。 It is very similar to yours with three differences:它与您的非常相似,但有三个不同之处:

  • SINGLE_BLOB instead of SINGLE_CLOB SINGLE_BLOB而不是SINGLE_CLOB
  • No need in CONVERT(XML, BulkColumn)不需要CONVERT(XML, BulkColumn)
  • DEFAULT clause is used for the LoadedDateTime column DEFAULT子句用于LoadedDateTime

Additionally, you can use SSIS for the task.此外,您可以将 SSIS 用于该任务。 SSIS has a streaming XML Source Adapter with no XML file size limitation. SSIS 有一个没有 XML 文件大小限制的流式 XML 源适配器。

SQL SQL

DECLARE @tbl TABLE(
    ID INT IDENTITY PRIMARY KEY,
    XmlData XML,
    LoadedDateTime DATETIME DEFAULT (GETDATE())
);

INSERT INTO @tbl(XmlData)
SELECT BulkColumn
FROM OPENROWSET(BULK N'C:\temp\PP015.xml', SINGLE_BLOB) AS x;

SELECT * FROM @tbl;

Thanks for the help but I found the solution.感谢您的帮助,但我找到了解决方案。 SQL has configurate a maxium characters retrieved for XML data. SQL 已配置为 XML 数据检索的最大字符数。 To solve this issue just we have to reconfigure this parameter.为了解决这个问题,我们只需要重新配置这个参数。

enter image description here在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM