mysql convert()

/**
http://forums.mysql.com/read.php?98,54553,54561
**/
You can use the CAST function. Here is some code to show you an example and the difference it makes in the results returned: 

mysql> SELECT CAST('19.45' AS DECIMAL(5,2)) as result; 
+--------+ 
| result | 
+--------+ 
| 19.45 | 
+--------+ 
1 row in set (0.04 sec) 

mysql> SELECT '19.45' - 19.45; 
+-----------------+ 
| '19.45' - 19.45 | 
+-----------------+ 
| 0 | 
+-----------------+ 
1 row in set (0.00 sec) 

mysql> SELECT CAST('19.45' AS DECIMAL(5,2)) - 19.45; 
+---------------------------------------+ 
| CAST('19.45' AS DECIMAL(5,2)) - 19.45 | 
+---------------------------------------+ 
| 0.00 | 
+---------------------------------------+ 
1 row in set (0.00 sec)

Jay Pipes 
Community Relations Manager, North America, MySQL Inc. 

Got Cluster? http://www.mysql.com/cluster 
Personal: http://jpipes.com

猜你喜欢

转载自jis117.iteye.com/blog/2090826
今日推荐