TSQL:在字符串中显式指定 NVARCHAR 有什么好处?

TSQL: Any benefits for explicitly specifying NVARCHAR in a string?(TSQL:在字符串中显式指定 NVARCHAR 有什么好处?)
本文介绍了TSQL:在字符串中显式指定 NVARCHAR 有什么好处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

当你添加一个新的 job_typesys.sp_cdc_add_job @job_type,
(属于 nvarchar(20) 类型)

When you add pass a new job_type to sys.sp_cdc_add_job @job_type,
(which is of type nvarchar(20))

您可以将参数传递为

  • N'清理'
  • 清理

使用前一种使用 N' 的语法将参数传递给存储过程有什么原因或好处吗?

Are there any reasons or benefits to use the former syntax using N' to pass the argument to stored procedures?

推荐答案

仅当字符串包含 unicode 字符时

Only if the string contains unicode characters

字符串在传递到存储过程时隐式转换为 nvarchar.

The string is implictly converted to nvarchar when the passed into the stored proc.

但是,在 SP 执行之前,它是一个没有 N 前缀的文字 varchar(字符串常量").因此,如果您使用日语名称,则需要N"以使其成为unicode 常量".请参阅 BOL 中的constants",其中详细介绍了常量...

However, before SP execution, it's a literal varchar ("character string constant") without N prefix. So, if you Japanese names, you'll need "N" to make it a "unicode constant". See "constants" in BOL which explains more about, er, constants...

受 Andomar 启发的测试...

A test of this inspired by Andomar...

CREATE PROCEDURE dbo.ZanziBar
   @KungFoo nvarchar(1)
AS
SET NOCOUNT ON
SELECT @KungFoo
GO

EXEC dbo.ZanziBar ''

EXEC dbo.ZanziBar N''

这篇关于TSQL:在字符串中显式指定 NVARCHAR 有什么好处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
SQL query to group by day(按天分组的 SQL 查询)
What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
Include missing months in Group By query(在 Group By 查询中包含缺失的月份)