substring
-- 문자열의 일부분만 가져오는 함수 substring()
-- 책 제목을 첫글자부터 열번째 글자까지만 가져오시오
-- substring 함수의 시작 위치는 1부터다
select substring(title,1,10) as title, pages, released_year
from books;
-- 제목을, 맨 뒤에서 5번째 글자부터 끝까지 다 나오도록 데이터를 가져오시오
select substring(title,-5) as title
from books;
-- 제목을 앞에서 3번째 글자부터 끝까지 다 나오도록 데이터를 가져오시오
select substring(title,3) as title
from books;
-- 책 제목을, 맨 앞부터 10까지만 가져오고, 뒤에는 ...을 붙여주세요
-- The Namesa...
select concat(substring(title,1,10),'...') as title
from books ;
replace
-- 문자열의 내용을 바꾸는 함수. replace()
-- 책 제목에, The가 있으면, Hello로 바꾸고싶다.
select replace(title,'The','Hello')
from books;
select replace(title,' ','->')
from books;
upper/lower
-- 대문자 / 소문자 변환함수 upper() / lower()
select replace(lower(title),'the','Hello') as title
from books;
select replace(upper(title),'the','Hello') as title
from books;
'MySQL' 카테고리의 다른 글
MySQL) 두 개의 테이블 조인하기 (2) | 2024.05.16 |
---|---|
MySQL) 데이터베이스 DATE(날짜) 가공하는 함수 (0) | 2024.05.16 |
MySQL) Reverse, Char_length, Ifnull 함수 사용하기 (0) | 2024.05.14 |
MySQL) LIKE, CASE, IF, GROUP BY 구문 사용하기 (0) | 2024.05.14 |
MySQL) 서브쿼리(Sub Query)와 Concat, Max, Min, Avg 함수 사용하기 (0) | 2024.05.14 |