sql raiserror 指定参数

标签 sql sql-server parameters

当我阅读 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/

相关文章:

sql - Where子句,返回至少满足三个条件中的两个条件的值

sql-server - SQL Server 双向级联?

java - 验证后Struts2清除参数

来自参数的Scala路径依赖返回类型

powershell - Powershell:在命令行中调用Powershell时,如何传递变量以切换参数?

sql - 如何将 SQL Server 数据库上传到共享主机环境?

php - 从表中选择类型为 int 和 varchar 的所有列

sql - 重复计数 - SQL

c# - PagedList 不会在 asp.net mvc 中进行真正的分页

sql-server - 将日期时间值设置为 SQL Server 中的变量的正确方法