Mysql decimal(m,d)的说明

Mysql decimal(m,d)的说明看了一些博客,觉得很多都是复制的,不如自己亲测一篇:createtabledecimal_test(idintauto_incrementPRIMARYkey,scoredecimal(5,2)–取值范围是-999.99到999.99);–整数的位数必须小于等于m-d,不然报错。小数的位数可以大于d位。多…

大家好,又见面了,我是你们的朋友全栈君。

看了一些博客,觉得很多都是复制的,不如自己亲测一篇:                          

create table decimal_test(
id int auto_increment PRIMARY key,
score decimal(5,2)  -- 取值范围是 -999.99 到 999.99
);

-- 整数的位数必须小于等于m-d,不然报错。小数的位数可以大于d位。多出d位时会做四舍五入,截取到d位。
-- 以上均不包括小数点、符号的位数。数字的总长度是m位,保存后的小数位最多是d位。如果保存后是整数,小数位不会补0。
-- 以下测试版本是5.7.14

select  *  from  decimal_test;
-- 正数:
insert into decimal_test(score) VALUES(1.23); -- 1.23
insert into decimal_test(score) VALUES(123.45); -- 123.45
insert into decimal_test(score) VALUES(123.455); -- 123.46
insert into decimal_test(score) VALUES(123.451); -- 123.45
insert into decimal_test(score) VALUES(123.451123); -- 123.45
insert into decimal_test(score) VALUES(12345.451123); -- Out of range value for column 'score' 
insert into decimal_test(score) VALUES(9999.451123); --  Out of range value for column 'score' 
insert into decimal_test(score) VALUES(999.451123234324); -- 999.45
insert into decimal_test(score) VALUES(999.999999999); -- Out of range value for column 'score' 
insert into decimal_test(score) VALUES(999.99123); -- 999.99
-- 负数:
insert into decimal_test(score) VALUES(-1.23); -- -1.23
insert into decimal_test(score) VALUES(-12.34); -- -12.34
insert into decimal_test(score) VALUES(-123.45); -- -123.45
insert into decimal_test(score) VALUES(-999.45); -- -999.45
insert into decimal_test(score) VALUES(-12343); -- Out of range value for column 'score' 
insert into decimal_test(score) VALUES(12343); -- Out of range value for column 'score' 
insert into decimal_test(score) VALUES(1234); -- Out of range value for column 'score' 
insert into decimal_test(score) VALUES(123); -- 123
insert into decimal_test(score) VALUES(-123); -- -123
insert into decimal_test(score) VALUES(-999.99); -- -999.99
insert into decimal_test(score) VALUES(-9990.99); -- Out of range value for column 'score'
insert into decimal_test(score) VALUES(-1234.99); -- Out of range value for column 'score'
insert into decimal_test(score) VALUES(-1234); -- Out of range value for column 'score' 

select   VERSION() ; -- 5.7.14



Mysql decimal(m,d)的说明

Mysql decimal(m,d)的说明 

 

Mysql decimal(m,d)的说明

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/160867.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • spring整合log4j_spring整合log4j

    spring整合log4j_spring整合log4j常用日志框架log4j、log4j2(log4j的升级版,最常用的)、logback(spring boot默认)、Jboss-logging…等slf4 是日志接口规范,代码对接slf4,实现和具体日志框架解耦,无需修改编码即可切换日志框架。修改pom依赖<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-st

    2022年8月9日
    7
  • pycharm的调试功能_安卓调试模式怎么打开

    pycharm的调试功能_安卓调试模式怎么打开Debug调试,是对于学习编程人员来说是一项重要的技能。只有当你学会debug了以后,才可以正确的知道程序的走向流程是如何的,DEBUG是排除程序故障的意思。debug则是通过工具来对代码进行调试,进而一步步找出程序中出现bug的位置,也就是程序中具体错误代码的位置。Pycharm中的debug模式首先,还是用示例说话,我们先写一段简短的代码,来帮助我们完成今天要讲的内容。初学者可能没见过for循环中的下划线‘_’,在Python中是占位符的意思,因…

    2022年8月28日
    4
  • idea 2021.10.3 激活码【2021最新】

    (idea 2021.10.3 激活码)好多小伙伴总是说激活码老是失效,太麻烦,关注/收藏全栈君太难教程,2021永久激活的方法等着你。https://javaforall.net/100143.htmlIntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,上面是详细链接哦~1STL5S9V8F-eyJsaWNlbnNlSWQiOi…

    2022年3月27日
    71
  • Deepin安装wxpython教程

    Deepin安装wxpython教程环境:安装报错:解决:1.sudoapt-getinstalllibgtk-3-dev-y    2.sudoapt-getinstallfreeglut3-devlibgstreamer-plugins-base1.0-dev-y3.sudopip3install-U-fhttps://extras….

    2022年5月21日
    35
  • 搭建Maven环境——使用本地的maven环境

    搭建Maven环境——使用本地的maven环境

    2021年8月28日
    54
  • idea2021.2.3激活码 3月最新注册码

    idea2021.2.3激活码 3月最新注册码,https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月15日
    166

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号