当前位置:网站首页>sql 字段类型转换
sql 字段类型转换
2022-07-27 16:28:00 【黑暗料理界的扛把子】
1、mysql vchar 转 int、double等
MySQL 的CAST()函数可用来获取一个类型的值,并产生另一个类型的值
cast()函数是一个转换函数,参数是一个表达式,它包括用AS关键字分隔的源值和目标数据类型。
cast 转换为double 类型,对于D\M取值注意事项。

#公式
CAST(value as type);
#vchar 转 int (小数会直接取整)
CAST(value as SIGNED);
#vchar 转 double M 代表保留整数位数+保留小数位数 ,D 代表保留小数位数
#1)参数m<65 是总个数,d<30且 d<m 是小数位。
#2)decimal可能的最大取值范围与double 一样,但是其有效的取值范围由M 和D 的值决定。
#如果改变M 而固定D,则其取值范围将随M 的变大而变大。
CAST(value as decimal(M,D));2、cast() 函数适用的转换类型
二进制,同带binary前缀的效果 : BINARY
字符型,可带参数 : CHAR()
日期 : DATE
时间: TIME
日期时间型 : DATETIME
浮点数 : DECIMAL
整数(有符号) : SIGNED
无符号整数 (无符号): UNSIGNED 3、cast() 和 convert() 的比较
相同点:都是进行数据类型转换,实现的功能基本等同
不同点:两者的语法不同,cast(value as type) 、 convert(value,type)
如有错误或者描述不准确,敬请指正。
边栏推荐
- WORD 2007+使用技巧
- I'm afraid I won't use the JMeter interface testing tool if I accept this practical case
- 自控原理学习笔记-系统稳定性分析(1)-BIBO稳定及Routh判据
- Sentinel1.8.4 persistent Nacos configuration
- WSN journal indexed by SCI
- Questions about webservice
- 如何用自动化测试搞垮团队
- Extension of ES6 value
- Kinect2 for Unity3D——AvatarDemo学习
- js常用utils封装
猜你喜欢

mysql学习笔记(1)——变量

Introduction to assembly language (1)

Unity learning notes (rigid body physics collider trigger)

自控原理学习笔记-系统稳定性分析(2)-环路分析及Nyquist-Bode判据

2022 preparation for autumn recruitment 10W word interview sketch PDF version, with operating system and computer network interview questions

C#与Mysql数据库交互-Mysql配置及增删查改操作

如何用自动化测试搞垮团队

转行软测&跳槽到新公司,工作怎样快速上手?

`this.$ Emit ` the child component passes multiple parameters to the parent component

C # interaction with MySQL database - MySQL configuration and addition, deletion, query and modification operations
随机推荐
NPM's ID card and dependence
kettle 合并记录 数据减少
Mongodb learning notes (1) - install mongodb and its related configurations
「测试新手百科」5 分钟快速上手Pytest 自动化测试框架
An article allows you to master threads and thread pools, and also solves thread safety problems. Are you sure you want to take a look?
Matrix of shell programming -- it's cute and cool
Resource for NS2 beginner
大冤种们,新进测试行业,如何正确选择意向企业?
Kinect2 for unity3d - avatardemo learning
ref 关键字的用法
Jmeter接口自动化-如何解决请求头Content-Type冲突问题
The understanding of string in C.
C # one method returns multiple values. Suggestions collection
web UI 自动化测试:Selenium 语法详解 史上最全
Unity显示Kinect捕获的镜头
ES6 new method
贪心法,拟阵和亚模函数(refer)
功率单位(power control)
Learning notes of Microcomputer Principles - common addressing methods
Docker - docker installation, MySQL installation on docker, and project deployment on docker