SQL Server 截断和 8192 限制
在 SQL Server 2005 中,我尝试查询 varchar(MAX) 列,该列的某些行的文本数据超过 8192。然而,在 Management Studio 中,我在 工具 --> 下找到了 选项 --> 查询结果--> 结果到文本 --> 每列显示的最大字符数 = 8192,这是最大值。 因此,这些行的截断似乎只是由于文本输出施加的限制而发生。
我认为解决这个问题的唯一方法是使用 SUBSTRING 函数来获取前 8000 个字符,然后是接下来的 8000 个字符,等等。但这很丑陋且容易出错。
我应该提到 SSIS 和 BCP 不是我的选择。
有人有更好的建议吗? 谢谢!
In SQL Server 2005 I am trying to query a varchar(MAX) column which has some rows with text data that exceed the 8192. Yet, In Management Studio I have under Tools --> Options --> Query Results --> Results to Text --> Max numbers of characters displayed in each column = 8192, which is a maximum. Accordingly, it seems the truncation on these rows occurs only due to the limitation imposed by text output.
The only thing I see to get around this is to use a SUBSTRING function to grab say the first 8000 chars, then the next 8000 chars etc. etc. But this is ugly and error prone.
I should mention that SSIS and BCP are not options for me.
Does anyone have a better suggestion? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
您可以将数据导出到不会被截断的平面文件。 为此:
其余步骤应该是不言自明的。 这会将文件输出为文本,您可以在您喜欢的文本编辑器中打开它。
You can export the data to a flat file which will not be truncated. To do this:
Remaining steps should be self explanatory. This will output the file to text and you can open it in your favorite text editor.
我也使用 XML,但 一种稍微不同的方法,它解决了 XML 实体化的大多数问题。
确保 SSMS 中的“XML 数据”限制设置得足够高!
I also use XML but a slightly different method that gets around most of the issues with XML entitisation.
Make sure that the "XML data" limit in SSMS is set sufficiently high!
您尝试过这个简单的解决方案吗? 只需点击 2 次即可!
在查询窗口中,
您将获得您想要在文件中看到的所有文本! 我可以看到 varchar(MAX) 字段的结果有 130,556 个字符
Did you try this simple solution? Only 2 clicks away!
At the query window,
You will get all the text you want to see in the file!!! I can see 130,556 characters for my result of a varchar(MAX) field
我的解决方案有点迂回,但让我到达了
(只要输出少于65535个字符):在SQL Management Studio中,将网格结果的限制设置为65535(工具> 选项 > 查询结果 > SQL Server > 结果到网格 >UPDATE:为了证明此操作有效,这里有一些选择单个 100,000 个字符列的 SQL。 如果我将网格输出保存到 csv 文件,则所有 100,000 个字符都在那里,没有截断。
注意:
My solution was a bit round-about but got me there
(as long as the output is less than 65535 characters):In SQL Management Studio, set the limit for grid results to 65535 (Tools > Options > Query Results > SQL Server > Results to Grid > Non XML data)UPDATE: To demonstrate that this works, here's some SQL that selects a single 100,000 character column. If I save the grid output to a csv file, all 100,000 characters are there with no truncation.
Notes:
我在尝试导出 XML 时遇到了这个问题。 这是我使用的解决方案:
选择“结果到网格”选项,右键单击“结果”窗格中显示的链接,然后选择“将结果另存为”,选择“所有文件”文件类型,为文件命名并单击“保存”。 所有 xml 数据都正确保存到文件中。
我正在使用 SSMS 10,但我无法让 Torre 的解决方案发挥作用。 导出向导一直认为输入列是图像:
“输入列“XML_F52E2B61-18A1-11d1-B105-00805F49916B”(26)”的数据类型是 DT_IMAGE
I ran in to this trying to export XML. This is the solution I used:
Select the Result to Grid option, right click the link that shows up in the Results pane, then select Save Results As, choose the All Files file type, give the file a name and click Save. All the xml data is saved correctly to a file.
I'm using SSMS 10, and I could't get Torre's solution to work. The export wizard kept thinking the input column was an image:
The data type for "input column "XML_F52E2B61-18A1-11d1-B105-00805F49916B" (26)" is DT_IMAGE
在 SSMS 中,如果您从一行中选择数据,则它仅限于少量字符,但如果您从一行中编辑数据,则完整值将在那里。 它可能并不总是在那里,但如果你按 ctrl-a、ctrl-c 然后在编辑器中将其过去,它就会全部在那里。
In SSMS if you select data from a row it is limited to a small number of characters, but if you Edit data from a row, the full value will be there. It might not always be there but if you ctrl-a, ctrl-c then past it in an editor it will all be there.
如果给定一个选择,我会让查询将数据返回为“For XML Auto”或“For XML Raw”或“For XML Explicit”,这样限制会更高,并且您可以对输出的结果执行更多操作。
If given a choice I would have the query return the data as "For XML Auto" or "For XML Raw" or "For XML explicit" that way the limitations are much higher and you can do much more with the outputed results.
我通常使用 XML 来获取巨大的调试字符串作为输出(使用 Luke 的测试工具):
I usually use XML to get huge debug string as output (using test harness from Luke):
另一种解决方法是使用 HeidiSql 来处理这个棘手的查询。 它没有字段长度的限制。
Another workaround , use HeidiSql for this tricky queries. It does not have the limits in the field lenght.
您所说的截断仅发生在 Management Studio 中。 如果您将该列拉入另一个应用程序,它不会被截断。
您无法使用查询分析器与 SQL Server 2005 对话。您是说 Management Studio 吗?
The truncation you are talking about only happens in Management Studio. If you pull the column into another app, it will not be truncated.
There's no way you're using Query Analyzer to talk to SQL Server 2005. Do you mean Management Studio?