mysql数字转换中⽂版_MYSQL字符数字转换
1.
将字符的数字转成数字,⽐如'0'转成0可以直接⽤加法来实现
例如:将pony表中的d 进⾏排序,可d的定义为varchar,可以这样解决
select * from pony order by (d+0)
2.
在进⾏ifnull处理时,⽐如 ifnull(a/b,'0') 这样就会导致 a/b成了字符串,因此需要把'0'改成0,即可解决此困扰
3⽐较数字和varchar时,⽐如a=11,b="11ddddd";
则 select 11="11ddddd"相等
若绝对⽐较可以这样:
select binary 11 =binary "11ddddd"
=======================================附录1======================================
字符集转换 :  CONVERT(xxx  USING  gb2312)
类型转换和SQL Server⼀样,就是类型参数有点点不同  : CAST(xxx  AS  类型)  ,  CONVERT(xxx,类型),类型必须⽤下列的类型:
可⽤的类型
⼆进制,同带binary前缀的效果 : BINARY
字符型,可带参数 : CHAR()
⽇期 : DATE
时间: TIME
⽇期时间型 : DATETIME
浮点数 : DECIMAL
整数 : SIGNED
⽆符号整数 : UNSIGNED
=======================================附录
2===============================================
To cast a string to a numeric value in numeric context, you normally do not have to do anything other than to use the string value as though it were a number:
mysql> SELECT 1+'1';
-> 2
If you use a number in string context, the number automatically is converted to a BINARY string.
mysql> SELECT CONCAT('hello you ',2);
mysql下载add produce-> 'hello you 2'
MySQL supports arithmetic with both signed and unsigned 64-bit values. If you are using numeric operators (such as + or -) and one of the operands is an unsigned integer, the result is unsigned. You can override this by using the SIGNED and UNSIGNED cast operators to cast the operation to a signed or unsigned 64-bit integer, respectively.
mysql> SELECT CAST(1-2 AS UNSIGNED)
-> 18446744073709551615
mysql> SELECT CAST(CAST(1-2 AS UNSIGNED) AS SIGNED);
-> -1
Note that if either operand is a floating-point value, the result is a floating-point value and is not affected by the preceding rule. (In this context, DECIMAL column values are regarded as floating-point values.)
mysql> SELECT CAST(1 AS UNSIGNED) - 2.0;
-> -1.0
If you are using a string in an arithmetic operation, this is converted to a floating-point number.
If you convert a “zero” date string to a date, CONVERT() and CAST() return NULL when the NO_ZERO_DATE SQL mode is enabled. As of MySQL 5.0.4, they also produce a warning.

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。