'mysql'에 해당되는 글 7건

  1. 2023.03.16 mysql 문자를 숫자로 변환
MySQL2023. 3. 16. 12:46

문자로 뽑아낸 값을 정수형 숫자로 변환해줘야하는 경우가 있다.

그럴때는, CAST 함수를 쓴다.

문자를 숫자로)

 

sql> SELECT CAST('1' as unsigned) FROM table;

 

 

그런데 반대로 하고싶다면..

char로 바꿀수도 있다.

 

 

sql> SELECT CAST(1 AS char(1)) FROM table; -- varchar는 CAST에 타입형으로 올수없음!

 

 

 

CAST type 종류는 binary, char, signed(부호있는 숫자), date, datetime, time, unsigned(부호없는 숫자) 등이 존재한다.

참고's)

https://dev.mysql.com/doc/refman/8.0/en/cast-functions.html#function_cast

Posted by 사슴영혼'-'