【问题标题】:SQL Server varchar(max) is not working properly [duplicate]SQL Server varchar(max) 无法正常工作 [重复]
【发布时间】:2020-06-04 02:54:33
【问题描述】:

在以下示例中,txt 列长度显示不正确。

CREATE TABLE dbo.test
(
    Id int IDENTITY,
    txt varchar(max)
);

insert into test(txt) select REPLICATE('0',8000);
insert into test(txt) select REPLICATE('00',8000);

select id, len(txt) from test;

drop table test;

两者的结果都是 8000。

有没有人可以帮忙?

【问题讨论】:

    标签: sql-server max varchar


    【解决方案1】:

    如果您想在 varchar(max) 列中插入一些内容 - 您的插入代码需要将其显式转换为 varchar(max) - 试试这个:

    insert into test(txt) select REPLICATE(cast('00' as varchar(max)), 8000);
    

    这应该会在表格中为您提供一个长度为 16'000 个字符的字符串。

    【讨论】:

      猜你喜欢
      • 2016-03-12
      • 1970-01-01
      • 1970-01-01
      • 2017-07-15
      • 2015-09-06
      • 2016-05-06
      • 2016-05-12
      • 2018-07-19
      • 2018-10-21
      相关资源
      最近更新 更多