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


相关推荐

  • 什么是单页面应用开发工具_单页面和多页面的区别及优缺点

    什么是单页面应用开发工具_单页面和多页面的区别及优缺点单页面应用开发MPA与SPA简介MPAMPA(Multi-pageApplication)多页面应用指的就是最传统的HTML网页设计,早期的网站都是这样的设计,所之称为「网页设计」。使用MPA在使用者浏览Web时会依据点击需求切换页面,浏览器会不停的重载页面(Reload),整个操作也常感觉卡卡。如果使用这样的设计在WebApp中,使用者体验比较差,整体流畅度扣分…

    2022年10月13日
    2
  • 图像半自动标注「建议收藏」

    图像半自动标注「建议收藏」前言标注数据集对深度学习而言是很重要的一步,但是标注数据是件很繁琐的工作,而半自动标注可以减轻工作量。Github(https://github.com/virajmavani/semi-auto-image-annotation-tool)上有一款自动标注工具,它以RetinaNet作为建议算法,使用预训练的RetinaNet模型从MSCOCO数据集建议80个类对象。这款工具我没有…

    2022年6月14日
    50
  • 周星驰算巨星吗_国际巨星女明星

    周星驰算巨星吗_国际巨星女明星4月1日,国际著名的技术先锋人物、领先的反病毒厂商卡巴斯基实验室的创始人&CEO尤金•卡巴斯基与巨星成龙一起,在北京奥运会中的标志性建筑“鸟巢”,举办了“卡巴斯基诚献-‘龙的传人’成龙和他的朋友们2009北京大型演唱会”的媒体见面会。在现场,尤金•卡巴斯基与成龙共同宣布,“卡巴斯基诚献-龙的传人-成龙和他的朋友们北京演唱会”将在一个月之后,也就是五月黄金周在“鸟巢”盛大开唱。这是卡巴…

    2022年8月20日
    8
  • intellij设置经典样式(背景为黑色的经典样式Darcula)

    intellij设置经典样式(背景为黑色的经典样式Darcula)将intellij设置为经典样式,背景黑色的Darcula样式。

    2022年6月27日
    28
  • eclipse代码自动补全[通俗易懂]

    eclipse代码自动补全[通俗易懂]1、点击菜单栏,打开Eclipse->Window->Perferences2、找到Java下的 Editor下的 ContentAssist,点击它3、找到第二个“AutoactivationtriggersforJava:”选项,在其后的文本框中会看到一个“.”存在。这表示:只有输入“.”之后才会有代码提示和自动补全,把该文本框中的“.”换成“abcdefghijklmnopqrstuvwxyz.”即可。…

    2022年5月31日
    33
  • 【crossbeam系列】3 crossbeam-deque:work-stealing算法

    【crossbeam系列】3 crossbeam-deque:work-stealing算法work-stealing算法简介crossbeam-deque包提供了一个无锁的双向队列(deque)。那么这个双向队列在并发中又起到了什么重要的作用呢?这就涉及到了在多任务环境下的一…

    2022年9月14日
    3

发表回复

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

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