본문 바로가기
Database/MYSQL

핸드폰번호 - 로 분리

by 반화넬 2007. 6. 4.
반응형
select
if(
length(phone_no)>10
,concat(substring(phone_no,1,3),"-",substring(phone_no,4,4),"-",substring(phone_no,8,4))
,concat(substring(phone_no,1,3),"-",substring(phone_no,4,3),"-",substring(phone_no,7,4))
) han_phone
from 테이블명

select
case when length(phone_no)<10 then 'min 10'
when  length(phone_no)=10 then
concat(substring(phone_no,1,3),"-",substring(phone_no,4,3),"-",substring(phone_no,7,4))
when  length(phone_no)=11 then
concat(substring(phone_no,1,3),"-",substring(phone_no,4,4),"-",substring(phone_no,8,4))
when length(phone_no>11) then 'max 11'
else 0
end
phoneno
,phone_no
from 테이블명
반응형