MySQL CAST 함수
페이지 정보
본문
CAST 함수는 type을 변경(지정)하는데 유용하다.
CAST 함수의 사용법은 다음과 같다.
CAST(expression AS type)
또는
CONVERT(expression,type)
타입은 다음중 하나이다.
BINARY
CHAR
DATE
DATETIME
SIGNED {INTEGER}
TIME
UNSIGNED {INTEGER}
【예제】
mysql> select cast(now() as date);
+---------------------+
| cast(now() as date) |
+---------------------+
| 2003-09-25 |
+---------------------+
1 row in set (0.00 sec)
mysql> select cast(1-2 as unsigned);
+-----------------------+
| cast(1-2 as unsigned) |
+-----------------------+
| 18446744073709551615 |
+-----------------------+
1 row in set (0.00 sec)
mysql> select cast(cast(1-2 as unsigned) as signed);
+---------------------------------------+
| cast(cast(1-2 as unsigned) as signed) |
+---------------------------------------+
| -1 |
+---------------------------------------+
1 row in set (0.00 sec)
mysql> select cast(1 as unsigned) -2.0;
+--------------------------+
| cast(1 as unsigned) -2.0 |
+--------------------------+
| -1.0 |
+--------------------------+
1 row in set (0.02 sec)
mysql>
자료출처
http://radiocom.kunsan.ac.kr/lecture/mysql/select_cast.html
댓글목록
등록된 댓글이 없습니다.