当前位置:网站首页>MySQL -- implicit conversion of data type
MySQL -- implicit conversion of data type
2022-07-24 18:26:00 【Xiao Xian.】
Recommended links :
summary ——》【Java】
summary ——》【Mysql】
summary ——》【Spring】
summary ——》【SpringBoot】
Mysql——》 Index storage model deduction
When two different types of data are operated on , In order to make them compatible ,MySQL Implicit data type conversions may be performed (Implicit type conversion)
One 、MySQL Automatically convert strings to numbers
- The string starts with a number , And all are numbers , Then the numerical result of conversion is the whole string
- The string starts with a number , And some are numbers , Then the converted numerical result is as of the first character that is not a number
- The string does not start with a number , Then the numerical result of conversion is 0
-- The string starts with a number , And all are numbers
SET @str1 := '123';
SELECT @str1 = 123;-- result :1, representative true
SELECT @str1 = '123';-- result :1 representative true
SELECT @str1 + 1;-- result :124
-- The string starts with a number , And some are numbers
SET @str2 := '123abc';
SELECT @str2 = 123;-- result :1, representative true
SELECT @str2 = '123';-- result :0, representative false
SELECT @str2 + 1;-- result :124
-- The string does not start with a number
SET @str3 := 'abc123';
SELECT @str3 = 123;-- result :0, representative false
SELECT @str3 = '123';-- result :0, representative false
SELECT @str3 + 100;-- result :100
Two 、MySQL Use functions to convert numbers to characters
-- CAST() Function to explicitly convert a number to a string
SELECT 1.1, CAST(1.1 AS CHAR);
-- CONCAT() Function implicitly converts a number to a string
SELECT 1.1, CONCAT(1.1);
3、 ... and 、 The official document describes implicit conversion
The following rules describe how the comparison operation is transformed :
- At least one of the two parameters is null when , The result of the comparison is null, In addition, use <=> The two one. null When making a comparison, it will return 1, There is no need for type conversion in either case
- Both parameters are strings , Compare by string , No type conversion
- Both arguments are integers , Compare... By integers , No type conversion
- When comparing hexadecimal values with non numeric values , It will be treated as a binary string
- One parameter is timestamp perhaps datetime, And the other parameter is constant , Constants are converted to timestamp
- One parameter is decimal type , If the other parameter is decimal Or an integer , Will convert integers to decimal Then compare , If the other parameter is a floating-point number , It will put decimal Convert to floating point for comparison
- In other cases , Both parameters are converted to floating-point numbers for comparison
边栏推荐
- epoch,batch_ size
- 根证书的有效期与服务器SSL证书一样长吗?
- Several sorting methods for while and sort
- Section 9 cache penetration follow Daewoo redis ------- directory posts
- Pytoch's journey 1: linear model
- Maximum sum and promotion of continuous subarrays (2)
- 空间三点画圆代码
- File upload vulnerability -.User.ini and.Htaccess
- Typora is still the most beautiful and beautiful document editing artifact of yyds in my heart. I believe you will never abandon it
- Template syntax [easy to understand]
猜你喜欢

模拟实现vector

Number of times a number appears in an ascending array

Missing value processing

缺失值处理

Icml2022 Best Paper Award: learning protein reverse folding from millions of predicted structures

Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag

The 5th Digital China Construction summit opened in Fuzhou, Fujian

Ionic4 learning notes 8 -- UI component 2 list (no practice, direct excerpt)

pycharm配置opencv库

Ionic4 learning notes 10 rotation map of an East Project
随机推荐
Ionic4 learning notes 11 - popular goods display of an East Project
Encapsulate function basedata.js
odoo中的bom理解
Several sorting methods for while and sort
A practical scheme of realizing 0.5px on mobile terminal
6. How to add an array in Es5?
第五届数字中国建设峰会在福建福州开幕
Ionic4 learning notes 8 -- UI component 2 list (no practice, direct excerpt)
Growth of operation and maintenance Xiaobai - week 8 of Architecture
根证书的有效期与服务器SSL证书一样长吗?
Section 9 cache penetration follow Daewoo redis ------- directory posts
ORM student management system
Three ways of redis cluster
jmeter -- prometheus+grafana服务器性能可视化
Problems needing attention in writing pages
Ionic4 learning notes 7 -- UI component 1 (no practice, direct excerpt)
epoch,batch_ size
Ionic4 Learning Notes 6 -- using native ionic4 components in custom components
Array object methods commonly used traversal methods & higher-order functions
数组对象方法 常用遍历方法&高阶函数