UTF-8字符另存为??在插入时保存,但在更新时正确保存 [英] UTF-8 characters get saved as ?? on insert, but gets saved correctly on update
问题描述
我在MS SQLServer上有一个带有nVarchar列的表.我正在使用插入语句保存UTF-8字符.它被保存为???.如果我通过update语句使用相同的值更新同一列,则会正确保存该列.
I have a table on MS SQLServer with an nVarchar column. I am saving a UTF-8 character using an insert statement. It gets saved as ???. If I update the same column using the same value via an update statement, it gets saved correctly.
关于这里的问题有什么暗示吗?使用的排序规则是:SQL_Latin1_General_CP1_CI_AS
Any hint on what would be the issue here? The collation used is : SQL_Latin1_General_CP1_CI_AS
推荐答案
显示您的插入语句. -很可能-缺少N
:
Show your insert statement. There is - quite probably - an N
missing:
DECLARE @v NVARCHAR(100)='Some Hindi from Wikipedia मानक हिन्दी';
SELECT @v;
结果:Some Hindi from Wikipedia ???? ??????
SET @v=N'Some Hindi from Wikipedia मानक हिन्दी';
SELECT @v;
结果:Some Hindi from Wikipedia मानक हिन्दी
字符串文字前面的N
告诉SQL-Server将内容解释为unicode
(确切地说,解释为ucs-2
).否则,它将被视为 1字节编码的扩展ASCII ,它不能处理所有字符...
The N
in front of the string literal tells SQL-Server to interpret the content as unicode
(to be exact: as ucs-2
). Otherwise it will be treated as a 1-byte-encoded extended ASCII, which is not able to deal with all characters...
这篇关于UTF-8字符另存为??在插入时保存,但在更新时正确保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!