개발공부

[MySQL] 문자열 교체 replace(), 거꾸로 변경 reverse(), 길이 구하기 char_length(), 대소문자 변경 upper(), lower() 본문

Database/MySQL

[MySQL] 문자열 교체 replace(), 거꾸로 변경 reverse(), 길이 구하기 char_length(), 대소문자 변경 upper(), lower()

mscha 2022. 5. 16. 12:03

books 테이블

1. 문자열 교체 함수 replace()

replace(원본, 교체하고 싶은 문자, 교체 후 문자)

title 컬럼에 들어있는 e를 3으로 바꿔서 가져오기.

select replace(title, 'e', '3')
from books;

 

2. 문자열의 순서를 거꾸로 바꾸는 함수 reverse()

'author_fname'을 뒤집어서 가져오기

select reverse(author_fname)
from books;

 

3. 문자열의 길이를 구하는 함수 char_length()

title의 길이를 구하기

select title, char_length(title) as length
from books;

 

4. 문자열의 대소문자 변경 함수 upper(), lower()

title 대문자로 변경

select UPPER(title)
from books;

 

title 소문자로 변경

select lower(TITLE)
from books;