問題描述
當(dāng)你添加一個(gè)新的 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)
)
您可以將參數(shù)傳遞為
N'
清理'- 清理
使用前一種使用 N'
的語法將參數(shù)傳遞給存儲(chǔ)過程有什么原因或好處嗎?
Are there any reasons or benefits to use the former syntax using N'
to pass the argument to stored procedures?
推薦答案
僅當(dāng)字符串包含 unicode 字符時(shí)
Only if the string contains unicode characters
字符串在傳遞到存儲(chǔ)過程時(shí)隱式轉(zhuǎn)換為 nvarchar.
The string is implictly converted to nvarchar when the passed into the stored proc.
但是,在 SP 執(zhí)行之前,它是一個(gè)沒有 N 前綴的文字 varchar(字符串常量").因此,如果您使用日語名稱,則需要N"以使其成為unicode 常量".請(qǐng)參閱 BOL 中的constants",其中詳細(xì)介紹了常量...
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 啟發(fā)的測(cè)試...
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'?'
這篇關(guān)于TSQL:在字符串中顯式指定 NVARCHAR 有什么好處?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!