当我阅读 MSDN 的示例时 raiserror
:
RAISERROR (N'This is message %s %d.', -- Message text.
10, -- Severity,
1, -- State,
N'number', -- First argument.
5); -- Second argument.
-- The message text returned is: This is message number 5.
GO
为什么文档使用
%s
指定 N'number'
,和 %d
指定 5
-- 第二个论点MSDN 是这样写的:
For example, in the following RAISERROR statement, the first argument of N'number' replaces the first conversion specification of %s; and the second argument of 5 replaces the second conversion specification of %d.
我的问题是:怎么解释呢?为什么不使用其他像
%a
或 %b
.任何其他 %+apha
可以代替它。我只是想得到一个有意义的理解。
最佳答案
这表示参数数据类型。
+--------------------+----------------------+
| Type specification | Represents |
+--------------------+----------------------+
| d or i | Signed integer |
| o | Unsigned octal |
| s | String |
| u | Unsigned integer |
| x or X | Unsigned hexadecimal |
+--------------------+----------------------+
N'number'
是 nvarchar
字符串字面量。所以得到 %s
说明符。和文字 5
是一个带符号的指标,所以用 %d
表示.至于这些说明符的原因。这记录在
RAISERROR
中话题These type specifications are based on the ones originally defined for the printf function in the C standard library
关于sql raiserror 指定参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19477547/