--测试数据 declare @table table (colname varchar(8)) insert into @table select '微•博' union all select '团•购' union all select '裸•婚' union all select '火•星•文' union all select '非•主•流' --查看结果 select * from @table /* colname -------- 微?博 团?购 裸?婚 火?星?文 非?主?流 */ --然后我们把上面的varchar改成nvarchar,再试一试 declare @tableA table (colname nvarchar(8)) insert into @tableA select '微•博' union all select '团•购' union all select '裸•婚' union all select '火•星•文' union all select '非•主•流' --查看结果 select * from @tableA /* colname -------- 微?博 团?购 裸?婚 火?星?文 非?主?流 */ --还是不行,然后我们在字符的前面加上N declare @tableB table (colname nvarchar(8)) insert into @tableB select N'微•博' union all select N'团•购' union all select N'裸•婚' union all select N'火•星•文' union all select N'非•主•流' --查看结果 select * from @tableB /* colname -------- 微•博 团•购 裸•婚 火•星•文 非•主•流 */ --这回就正常了。 /* 如果是varchar类型的,加上N也不好使的。 那么这个N是干什么用的呢? 字符串参数值的前面有一个大写的N,它的含义是表明后面引号里的字符串是unicode。 总结一下: 1、类似问题就是要保证列的类型是nvarchar; 2、插入数据的时候保证数据是unicode的。 这样就不会显示莫名其妙的问号了。 */
SELECT的结果中出现"乱码"的解决方案--【叶子】
最新推荐文章于 2021-01-20 19:29:36 发布