[DB] Oracle Query 문제 정리

Hadam Cho·2021년 5월 23일

Database

목록 보기
3/8
post-thumbnail

like

-- 가로 시작하고 이름이 두 글자인 사람
select *
from player_t
where player_name like '가_';

-- 이름 두 번째 글자가 '수'인 선수들의 이름과 영문 이름 조회
select player_name, e_player_name
from player_t
where player_name like '_수%';

not

-- 포지션이 GK, MF, FW, DF, TC가 모두 아닌 선수들만 이름과 포지션 조회
select player_name, position
from player_t
where not position in ('GK', 'MF', 'FW', 'DF', 'TC');

select player_name, position
from player_t
where not position = any ('GK', 'MF', 'FW', 'DF', 'TC');

select player_name, position
from player_t
where position != all ('GK', 'MF', 'FW', 'DF', 'TC');

-- 영문 이름에 T 문자가 하나도 포함되지 않는 선수들만 이름, 영문 이름을 조회하시오.
select player_name, e_player_name
from player_t
where not e_player_name like '%T%';

문자 함수

 -- player_t 선수 중에서 이름이 1글자, 3글자가 아닌 선수들의 이름을 아래 형태대로 출력하시오.
 -- 이름첫글자**남은 글자
 select substr(player_name, 1, 1) || '**' || substr(player_name, 2)
 from player_t
 where length(player_name) not in (1, 3);

날짜 함수

-- player_t 선수들의 [이름, 생일, 만나이]를 조회하시오. (예: 만 27세 8개월)
select player_name, birth,
	'만 ' || trunc(months_between(sysdate, birth) / 12) || '세 ' ||
    trunc(mod(months_between(sysdate, birth), 12)) || '개월'
from player_t;
profile
(。・∀・)ノ゙

0개의 댓글