mysql> SELECT CONCAT ( CAST(1 as char) , '2') AS test
+------+
| test |
+------+
| 12 |
+------+
1 row in set (0.00 sec)
mysql> SELECT CONCAT ( Convert(1, char) , '2') AS test
+------+
| test |
+------+
| 12 |
+------+
1 row in set (0.00 sec)
字符转数字
mysql> SELECT CAST('1' as SIGNED) + 100 AS test
+------+
| test |
+------+
| 101 |
+------+
1 row in set (0.00 sec)
mysql> SELECT Convert('1' , SIGNED) + 100 AS test
+------+
| test |
+------+
| 101 |
+------+
1 row in set (0.00 sec)
1.varchar转int
函数:cast
用法:cast(字段 as SIGNED INTEGER)
或者cast(字段 as UNSIGNED INTEGER))
例如:SELECT CAST(DATE_FORMAT(NOW(),"%Y%m%d") as SIGNED INTEGER)
2.varchar转date
函数:str_to_date(字段,字符串格式)
用法:select str_to_date(字段,'%Y-%m-%d') from tablea limit 100;
根据日期进行选取
选取日期大于2019年的所有字段
例如:select * from tablea where str_to_date(tablea.日期,'%Y-%m-%d')>'2019-00-00'
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)