为什么 SQL Server 在将 int 转换为数据类型 numeric 时抛出算术溢出错误? [英] Why SQL Server throws Arithmetic overflow error converting int to data type numeric?

查看:271
本文介绍了为什么 SQL Server 在将 int 转换为数据类型 numeric 时抛出算术溢出错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在运行此代码时,SQL Server Management Studio 抛出了一个错误:

I have an error being thrown by SQL Server Management Studio when running this code:

declare @percentage numeric(3,2)
set @percentage = cast(15 as numeric(3,2))

但是当我将数字声明更改为

but when I change numeric declaration to

declare @percentage numeric(4,2)
set @percentage = cast(15 as numeric(4,2))

一切顺利.

数字数据类型有限制吗?

Is there a limitation for numeric data type?

推荐答案

Numeric 定义 TOTAL 位数,然后是小数点后的数字.

Numeric defines the TOTAL number of digits, and then the number after the decimal.

一个 numeric(3,2) 最多只能容纳 9.99.

A numeric(3,2) can only hold up to 9.99.

这篇关于为什么 SQL Server 在将 int 转换为数据类型 numeric 时抛出算术溢出错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆