8192 导出到文件时文本列有限制吗?

发布于 2024-11-27 10:42:51 字数 290 浏览 2 评论 0原文

我看过 this 问题,本质上是相同的,但 OP 接受了'使用其他工具作为答案。基本上,我试图将数据从表导出到分隔文件,但由于 8192 个字符的限制,输出文本被截断。我找不到任何有效的好方法(至少对我来说)。

如果 SSMS 和 sqlcmd (不确定该限制是否也适用于此。我目前正在尝试)是我唯一的选择,有没有办法解决此限制并转储较高宽度的文本列?

I have looked at this question which is essentially the same but the OP accepted 'using other tools' as an answer. Basically, I am trying to export data from a table to a delimited file but because of the 8192 character limit, the output text is getting truncated. I could not find any good approaches that work (for me at least).

If SSMS and sqlcmd (not sure if the limitation applies to this as well. I am trying at the moment) are my only options, is there a way to workaround this limitation and dump text columns of higher widths?

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

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

发布评论

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

评论(1

从来不烧饼 2024-12-04 10:42:51

您是否考虑过使用简单的 PowerShell 脚本或使用 C# 的命令行应用程序?如果它可以SELECT所有数据,那么它当然应该能够将其全部写入文件。

编辑 2011-08-03

我无法使用 PowerShell 或 sqlcmd 来实现此功能。前者似乎将输出截断为 4000 个字符,后者截断为 256 个字符。然而,我的好老朋友 VBScript 再次证明,新的和闪亮的并不总是最好的……代码写起来要乏味得多,但它有效。另存为 .vbs 文件,对第 2、3 和 6 行(如果需要更多列、数据转换、不同分隔符等,则对第 9 行进行适当更改)。

set conn = createobject("ADODB.Connection")
conn.open "provider=SQLOLEDB.1;data source=.;user id=user;password=pass;"
set rs = conn.execute("SELECT VarcharMaxCol FROM dbo.TableName")

set fso = createobject("Scripting.FileSystemObject")
set f = fso.CreateTextFile("c:\path\from_vbs.csv", true)

do while not rs.eof
    f.writeline vbCrLf & rs(0)
    rs.movenext
loop

rs.close   : set rs   = nothing
conn.close : set conn = nothing
f.close    : set f    = nothing
set fso  = nothing

如果我从我的 PowerShell 专家朋友那里得到关于他们如何处理 > 的任何答案,我会在这里发帖。 4K。

Have you considered using a simple PowerShell script or a command-line app using C#? If it can SELECT all of the data then it should certainly be able to write it all to a file.

EDIT 2011-08-03

I was unable to get this working with PowerShell or sqlcmd. The former seems to truncate output at 4000 characters and the latter at 256. However my good old friend VBScript once again proved that new and shiny is not always the best... the code is much more tedious to write, but it works. Save as .vbs file, make the appropriate changes to lines 2, 3 and 6 (and 9 if you want more columns, transformation of the data, different delimiters, etc).

set conn = createobject("ADODB.Connection")
conn.open "provider=SQLOLEDB.1;data source=.;user id=user;password=pass;"
set rs = conn.execute("SELECT VarcharMaxCol FROM dbo.TableName")

set fso = createobject("Scripting.FileSystemObject")
set f = fso.CreateTextFile("c:\path\from_vbs.csv", true)

do while not rs.eof
    f.writeline vbCrLf & rs(0)
    rs.movenext
loop

rs.close   : set rs   = nothing
conn.close : set conn = nothing
f.close    : set f    = nothing
set fso  = nothing

I will post back here if I get any answers from my PowerShell guru friends about how they deal with > 4K.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文