忽略 microsoft sql server 中的算术溢出
我正在 SQLServer 中进行一些操作.并且遇到了著名的算术溢出"错误.情况是,我希望它溢出.我如何告诉它允许溢出并忽略错误?
I'm doing some bit manipulations in SQLServer. And have encountered the famous "Arithmetic Overflow" error. The case is, I want it to overflow. How can I tell it to allow overflow and ignore the error?
我正在做这个选择:
SELECT CONVERT(bigint, 0x8000000000000000)-1
我希望它返回 9223372036854775807(最大的 bigint),但它返回:
I want this to return 9223372036854775807 (the biggest bigint), but it returns:
Arithmetic overflow error converting expression to data type bigint.
推荐答案
这个怎么样:
SET ARITHABORT OFF;
SET ARITHIGNORE ON;
SET ANSI_WARNINGS OFF;
SELECT ISNULL(CONVERT(bigint, 0x8000000000000000)-1, 9223372036854775807)
请参阅关于 ARITHIGNORE 和 ARITHABORT
相关文章