You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MySQL无法插入DECIMAL值:ER_WARN_DATA_OUT_OF_RANGE错误求助

Alright, let's figure out why you're hitting that "Out of range value" error and fix it up.

Root Cause of the Error

Your DECIMAL(4,4) column definition is the issue here. Let's break down how the DECIMAL(M,D) type works in MySQL:

  • M = total number of digits (integer + fractional parts combined, not counting the decimal point)
  • D = number of digits reserved exclusively for the fractional part

When you set DECIMAL(4,4), you're allocating all 4 available digits to the fractional portion. That means the integer part can only be 0—valid values are between -0.9999 and 0.9999. All your insert values (like 5.5, 8.2, or 10) have integer parts greater than 0, so they're way outside this range, triggering the error.

Solution: Adjust the DECIMAL Precision

You need to tweak the DECIMAL parameters to match your actual data range. Looking at your sample inserts:

  • The largest integer value is 10 (2 digits)
  • Most values have 1 fractional digit (e.g., 5.5, 9.1)

A perfect fit here would be DECIMAL(3,1):

  • 3 total digits (2 for the integer part, 1 for the fractional)
  • Supports values from -99.9 to 99.9, which covers all your sample data (including 10, which will be stored as 10.0).

Run this ALTER statement to update the column:

ALTER TABLE relationship MODIFY COLUMN student_grade DECIMAL(3, 1);

If you ever need more fractional precision (e.g., two decimal places like 5.50), switch to DECIMAL(4,2) instead—it allows integers up to 99 with two decimal digits.

Verify the Fix

After updating the column, your existing INSERT statements will run without errors. For example, 10 will be stored as 10.0 in the DECIMAL(3,1) column, which is fully valid.

内容的提问来源于stack exchange,提问作者Dronius

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 10:10:31