sql raiserror specify parameter

一世执手 提交于 2019-12-10 19:06:41

问题


When i read the example of 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

Why the doc using %s to specify the N'number',and %d to specify the 5 -- Second argument

The MSDN write like this:

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.

My question is: How can explain it? Why don't using other like %a or %b.Any other %+apha can replace it. I just want to get a meaningful understand.


回答1:


This represents the parameter datatype.

+--------------------+----------------------+
| Type specification |      Represents      |
+--------------------+----------------------+
| d or i             | Signed integer       |
| o                  | Unsigned octal       |
| s                  | String               |
| u                  | Unsigned integer     |
| x or X             | Unsigned hexadecimal |
+--------------------+----------------------+

N'number' is an nvarchar string literal. So gets the %sspecifier. And the literal 5 is a signed indicator so is represented by %d.

As for the reason for these specifiers. This is documented in the RAISERROR topic

These type specifications are based on the ones originally defined for the printf function in the C standard library



来源:https://stackoverflow.com/questions/19477547/sql-raiserror-specify-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!