码迷,mamicode.com
首页 > 其他好文 > 详细

转换函数

时间:2015-05-31 20:08:36      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:

SELECT EMP_ID, CAST(EMP_ID AS UNSIGNED) FROM EMPLOYEE_TBL;
+-----------+--------------------------+
| EMP_ID    | CAST(EMP_ID AS UNSIGNED) |
+-----------+--------------------------+
| 213764555 |                213764555 |
| 220984332 |                220984332 |
| 311549902 |                311549902 |
| 313782439 |                313782439 |
| 442346889 |                442346889 |
| 443679012 |                443679012 |
+-----------+--------------------------+

SELECT PAY_RATE, CAST(PAY_RATE AS CHAR) 
    -> FROM EMPLOYEE_PAY_TBL;
+----------+------------------------+
| PAY_RATE | CAST(PAY_RATE AS CHAR) |
+----------+------------------------+
|     NULL | NULL                   |
|    11.00 | 11.00                  |
|     NULL | NULL                   |
|     NULL | NULL                   |
|    14.75 | 14.75                  |
|    15.00 | 15.00                  |
+----------+------------------------+

SELECT PAY_RATE, CAST(PAY_RATE AS CHAR) FROM EMPLOYEE_PAY_TBL WHERE PAY_RATE IS NOT NULL;
+----------+------------------------+
| PAY_RATE | CAST(PAY_RATE AS CHAR) |
+----------+------------------------+
|    11.00 | 11.00                  |
|    14.75 | 14.75                  |
|    15.00 | 15.00                  |
+----------+------------------------+

SELECT LAST_NAME, FIRST_NAME, EMP_ID FROM EMPLOYEE_TBL ORDER BY EMP_ID;
+-----------+------------+-----------+
| LAST_NAME | FIRST_NAME | EMP_ID    |
+-----------+------------+-----------+
| GLASS     | RBANDON    | 213764555 |
| WALLACE   | MARIAH     | 220984332 |
| STEPHENS  | TINA       | 311549902 |
| GLASS     | JACOB      | 313782439 |
| PLEW      | LINDA      | 442346889 |
| SPURGEON  | TIFFANY    | 443679012 |
+-----------+------------+-----------+

SELECT CONCAT(LAST_NAME, , , FIRST_NAME) AS NAME, CONCAT(SUBSTR(EMP_ID, 1, 3), -, SUBSTR(EMP_ID, 4, 2), -, SUBSTR(EMP_ID, 6, 4)) AS ID FROM EMPLOYEE_TBL ORDER BY ID;
+-------------------+-------------+
| NAME              | ID          |
+-------------------+-------------+
| GLASS, RBANDON    | 213-76-4555 |
| WALLACE, MARIAH   | 220-98-4332 |
| STEPHENS, TINA    | 311-54-9902 |
| GLASS, JACOB      | 313-78-2439 |
| PLEW, LINDA       | 442-34-6889 |
| SPURGEON, TIFFANY | 443-67-9012 |
+-------------------+-------------+

SELECT CONCAT(LAST_NAME, , , FIRST_NAME) AS NAME, CONCAT(SUBSTR(EMP_ID, 1, 3), -, SUBSTR(EMP_ID, 4, 2), -, SUBSTR(EMP_ID, 6, 4)) AS ID FROM EMPLOYEE_TBL ORDER BY 1;
+-------------------+-------------+
| NAME              | ID          |
+-------------------+-------------+
| GLASS, JACOB      | 313-78-2439 |
| GLASS, RBANDON    | 213-76-4555 |
| PLEW, LINDA       | 442-34-6889 |
| SPURGEON, TIFFANY | 443-67-9012 |
| STEPHENS, TINA    | 311-54-9902 |
| WALLACE, MARIAH   | 220-98-4332 |
+-------------------+-------------+

 

转换函数

标签:

原文地址:http://www.cnblogs.com/fatoland/p/4542385.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!