TSQL: Any benefits for explicitly specifying NVARCHAR in a string?(TSQL:在字符串中显式指定 NVARCHAR 有什么好处?)
问题描述
当你添加一个新的 job_type 到 sys.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 有什么好处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:TSQL:在字符串中显式指定 NVARCHAR 有什么好处?
基础教程推荐
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 无法解决整理冲突 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
