简体   繁体   English

NVARCHAR(MAX)无法容纳50478个字符

[英]NVARCHAR(MAX) doesn't accommodate 50478 characters

I'm trying to store a string of 50478 characters length in a nvarchar(max) database field. 我正在尝试在nvarchar(max)数据库字段中存储长度为50478个字符的字符串。 According to this link , it tells that a nvarchar(max) field can store up to 1 billion characters, but when I tried to store just 50478 characters sql truncates them and doesn't store the full string. 根据此链接 ,它告诉我们nvarchar(max)字段最多可以存储10亿个字符,但是当我尝试仅存储50478个字符时,sql将其截断并且不存储完整字符串。

How to solve such a problem? 如何解决这样的问题?

Do you think that this is just a printing problem with sql server management studio? 您是否认为这只是SQL Server Management Studio的打印问题?

You need to ensure that the data being inserted into the field is cast as nvarchar too otherwise you will not be able to achieve what you're looking for. 您需要确保将插入字段的数据也强制转换为nvarchar,否则将无法实现所需的功能。

Take this as an example: 以此为例:

Create table #temp (this nvarchar(max))

insert into #temp values (REPLICATE(cast('a' as nvarchar(max)), 50478))

Select this, Len(this) from #temp

drop table #temp

Also can be viewed on SQL Fiddle here: http://sqlfiddle.com/#!6/551f7/2/0 也可以在以下SQL Fiddle上查看: http ://sqlfiddle.com/#!6/551f7/2/0

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

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