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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Matlab 2016a 安装包及破解教程

    Matlab 2016a 安装包及破解教程Matlab-Matlab2016a安装破解教程本方法只是研究破解技术所用。如果要使用软件还是要用正版的。Matlab2016a安装包及破解教程百度云分享链接: 链接:https://pan.baidu.com/s/1i6BgD8p    密码:17gg Matlab安装教程: 1、下载文件,得到R2016a_win64.part1.rar、R2016a_…

    2022年5月1日
    268
  • 有趣的10个CMD命令「建议收藏」

    有趣的10个CMD命令「建议收藏」有趣的10个CMD命令

    2022年9月22日
    2
  • 一篇文章揭穿创业公司的套路「建议收藏」

    一篇文章揭穿创业公司的套路

    2022年2月15日
    62
  • 分享67套基于Java开发的Java毕业设计实战项目(含源码+毕业论文)【新星计划】

    分享67套基于Java开发的Java毕业设计实战项目(含源码+毕业论文)【新星计划】【新星计划】分享67套基于Java开发的Java毕业设计实战项目(含源码+毕业论文)基于Java开发的Java毕业设计实战项目本文中的所有主题都来自互联网。如果您侵犯您的权利,请及时联系Blogger,博主将及时处理。投诉邮箱:1919101926@qq.com(没事勿扰,不接单,也没时间解决难题,谢谢配合)。文章目录->建议收藏关注+点赞<-基于Java开发的Java毕业设计实战项目前言Java毕业设计所用到的开发环境Java毕业设计项目简单介绍17套基于Java开发的[互

    2022年9月1日
    5
  • matlab中importdata函数导入数据 到工作空间[通俗易懂]

    用load函数导入mat文件大家都会。但是今天我拿到一个数据,文件后缀名居然是‘.data’。该怎么读呢?我只好用matlab界面Workspace区域的“importdata”按钮手工导入该文件。恩,还好,居然成功了。顺便提一下,这个“importdata”按钮功能很强大,连excel文件都能导入。但是如果在脚本里如何导入这种非mat文件呢?这时候就轮到“import

    2022年4月17日
    223
  • 个性化推荐算法总结[通俗易懂]

    个性化推荐算法总结[通俗易懂]读书笔记|《推荐系统实践》-个性化推荐系统总结对于推荐系统,本文总结内容,如下图所示:一、什么是推荐系统1.为什么需要推荐系统为了解决互联网时代下的信息超载问题。2.搜索引擎与推荐系统分类目录,是将著名网站分门别类,从而方便用户根据类别查找公司。 搜索引擎,用户通过输入关键字,查找自己需要的信息。 推荐系统,和搜索引擎一样,是一种帮助用户快速发展有用信…

    2022年5月2日
    36

发表回复

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

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