如何从 SQL Server 数据库中可视化 nvarchar(max) 的值(max>65535)?

发布于 2024-10-04 21:25:48 字数 584 浏览 4 评论 0原文

可能的重复:
SQL Server Management Studio:增加字符数结果集中显示的字符
更新:注意:该讨论包含标记为答案的不正确答案。

SQL Server 2008 R2 中的 SSMS 允许在“结果到文本”模式下可视化最多 8192 个字符,在“结果到网格”模式下可视化最多 65535 个字符。 “要归档的结果”也被截断。

如何快速且便宜地查看较大尺寸的选定值?

更新:
我看到了之前的讨论,最好的答案是创建我自己的前端应用程序,这并不是真正的答案。
我不打算与 DBMS 客户端工具供应商竞争。
我只需要快速、肮脏或廉价地看到价值,无论是工具还是不是工具。

我简直不敢相信,为了看到单个值,我应该创建客户端应用程序,并且没有任何技巧或解决办法。

Possible Duplicate:
SQL Server Management Studio: Increase number of characters displayed in result set
Update: Note: that discussion contains INCORRECT answer marked as answer.

SSMS from SQL Server 2008 R2, permits to visualize maximum of 8192 characters in "Results to text" mode and 65535 in "Results to grid" mode. "Results to file" are also truncated.

How can I see the selected value of bigger size fast and cheap?

Update:
I saw previous discussion and the best answer is to create my own front-end app is not really an answer.
I am not planning to compete with DBMS client tools vendors.
I just need to see the value fast, dirty or cheap, be it tools or not tools.

I just cannot believe that in order to see a single value I should create client applications and there is no trick or way around.

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

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

发布评论

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

评论(5

只涨不跌 2024-10-11 21:25:48

为什么不直接以 XML 形式返回数据集并且没有大小限制?您可以使用强制转换(COLUMN_NAME as XML)来执行此操作。

替代文字

Why don't you just return the dataset as XML and there are no size limitations? You can do this using the cast( COLUMN_NAME as XML ) to do this.

alt text

北座城市 2024-10-11 21:25:48

又快又脏,我喜欢这样。当然,这可以在 Management Studio 内部完成,您只需要有一点创意即可。这个想法很简单——无法显示整个字符串?将其切碎并显示更多行。
这是一个函数,它采用 varchar 输入并输出具有指定大小块的表。然后,您可以使用此功能从原始表中进行 CROSS APLLY 选择并获得您需要的内容。

功能:

create function Splitter( @string varchar(max), @pieceSize int ) 
returns @t table( S varchar(8000) )
as
begin
    if ( @string is null or len(@string) = 0 )
        return

    set @pieceSize = isnull(@pieceSize, 1000)       
    if (@pieceSize < 0 or @pieceSize > 8000)
        set @pieceSize = 8000

    declare @i int = 0
    declare @len int = len(@string)

    while ( @i < @len / @pieceSize  )
    begin
        insert into @t(S) values(substring( @string, @i * @pieceSize + 1, @pieceSize))
        set @i = @i + 1
    end

    if (@len % @pieceSize) != 0
    begin
        if (@len / @pieceSize) = 0
            set @i = 1

        insert into @t(S) values(substring( @string, (@i - 1) * @pieceSize + 1, @len % @pieceSize ))
    end 
    return      
end

使用示例:

select t.ID, t.Col1, t.Col2, t.Col3, pieces.S
from dbo.MyTable as t
cross apply dbo.Splitter( t.MybigStringCol, 1000 ) as pieces

Quick and dirty, I like that. Of course it can be done from inside Management Studio, you just have to be little creative. The idea is simple - can't display the whole string? Chop it up and display more rows.
Here is a function that takes a varchar input and outputs table with chunks of specified size. You can then CROSS APLLY select from from original table with this function and get what you need.

Function:

create function Splitter( @string varchar(max), @pieceSize int ) 
returns @t table( S varchar(8000) )
as
begin
    if ( @string is null or len(@string) = 0 )
        return

    set @pieceSize = isnull(@pieceSize, 1000)       
    if (@pieceSize < 0 or @pieceSize > 8000)
        set @pieceSize = 8000

    declare @i int = 0
    declare @len int = len(@string)

    while ( @i < @len / @pieceSize  )
    begin
        insert into @t(S) values(substring( @string, @i * @pieceSize + 1, @pieceSize))
        set @i = @i + 1
    end

    if (@len % @pieceSize) != 0
    begin
        if (@len / @pieceSize) = 0
            set @i = 1

        insert into @t(S) values(substring( @string, (@i - 1) * @pieceSize + 1, @len % @pieceSize ))
    end 
    return      
end

Usage example:

select t.ID, t.Col1, t.Col2, t.Col3, pieces.S
from dbo.MyTable as t
cross apply dbo.Splitter( t.MybigStringCol, 1000 ) as pieces
美男兮 2024-10-11 21:25:48

这就是问题所在,我在 sqlise 中攻击 SQLPSX codeplex 项目的 PowerShell 模块(抱歉,我只允许在超链接上使用,请谷歌搜索)。
PowerShell ISE 是集成脚本环境,是 PowerShell V2 的一部分。
SQLPSX 是针对管理和查询 MS-SQLserver 的 PowerShell 模块的集合(以及对 ORACLE 的最低支持)。
ISE 的正常输出窗格有一些不良的截断/换行行为,但可以将输出发送到编辑器窗格。
当使用获取一列宽结果集中的单行并使用“inline”或“isetab”作为输出格式的查询时,您将获得完整的 varchar(max)、text、CLOB(是的,这也适用于 ORACLE)值。
如果您查询包含此类列的单行,结果取决于嵌入的换行符,当前设置的宽度为 10000 个字符/行。但这是脚本语言,你可以自己修改。

如果您更喜欢纯 T-SQL 解决方案,可以查看我的项目 Extreme T-SQL Script 的源代码 http:// etsql.codeplex.com/。使用脚本 print_string_in_lines.sql 和 sp_gentextupdate.sql,您可以使用工具生成更新脚本以将字段设置为当前内容。需要 SQL-SERVER 2008,因为我内部使用 varchar(max)。

顺便说一句,我无法访问 SQL Server 2008 R2。我认为限制仍然是每个文本列 4000 个字符左右。

我希望这有帮助
贝恩德

That is the problem, I attack in sqlise a PowerShell module of the SQLPSX codeplex project (sorry I'm only allowed to use on hyperlink please google for it).
PowerShell ISE is the Integrated Scripting Environment which is part of PowerShell V2.
SQLPSX is a collection of PowerShell modules targeting management and querying MS-SQLserver (and minimal support for ORACLE too).
The normal output-pane of ISE has some bad truncation/wrapping behaviour, but it is possible to send out-put to an editor pane.
When use a query that fetches a single row of a one column wide resultset and use either 'inline' or 'isetab' as output format, you get the complete varchar(max), text, CLOB (yes this works for ORACLE too) value.
If you query a single row with such columns, the result depends on embedded linefeeds, a width of 10000 chars / line is current set. But that is in a script language and you can modify it by yourself.

If you prefer a pure T-SQL solution, you can look a the source of my project Extreme T-SQL Script http://etsql.codeplex.com/. With the scripts print_string_in_lines.sql and sp_gentextupdate.sql you have the tools to generate update scripts to set fields to the current content. SQL-SERVER 2008 is required, as I internally use varchar(max).

BTW I don't have access to SQL Server 2008 R2. I though the limit is still about 4000 characters per text column.

I hope that helps
Bernd

莳間冲淡了誓言ζ 2024-10-11 21:25:48
Select
    CASE WHEN T.TheSegment = 1 Then Cast(T.SomeID as varchar(50)) 
         Else '' 
    End as The_ID
    , T.ChoppedField
From  (
   Select SomeID
       , 1 as TheSegment
       , substring(SomeBigField, 1, 8000) as ChoppedField
    from sometable
    Union All
    Select SomeID
       , 2
       , substring(SomeBigfield, 8001, 16000)
    from sometable
) as t
order by t.SomeID, t.TheSegment;

如有必要,请在联合上冲洗并重复,或者随意递归;不知道超过 16000 个字符您还想读多少。大约尽可能便宜。

很多时候,这些大字段包含格式化字符,因此创建自己的表单和使用某种类型的富文本控件的建议是有效的。

Select
    CASE WHEN T.TheSegment = 1 Then Cast(T.SomeID as varchar(50)) 
         Else '' 
    End as The_ID
    , T.ChoppedField
From  (
   Select SomeID
       , 1 as TheSegment
       , substring(SomeBigField, 1, 8000) as ChoppedField
    from sometable
    Union All
    Select SomeID
       , 2
       , substring(SomeBigfield, 8001, 16000)
    from sometable
) as t
order by t.SomeID, t.TheSegment;

Rinse and repeat if necessary on the unions or feel free to get recursive; not sure how much more than 16000 characters you feel like reading. About as cheap as it gets.

Many times these large fields contain formating characters, so the suggestions for creating your own form and using some type of richtext control are valid.

ぶ宁プ宁ぶ 2024-10-11 21:25:48

您可以通过在前端应用程序中查看它来看到它。 SSMS 并非设计为通用数据查看器。

You can see it by viewing it in your front-end application. SSMS is not designed to be a general data viewer.

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