[ORACLE] MYSQL과의 차이

이도원·2022년 11월 24일
0

DB

목록 보기
2/2
--별칭(as생략 가능), 별칭 한글이나 숫자쓸때 ""로 묶어야댐 (''는 안댐)
--별칭 group by, having에서 사용불가
--DATE_FORMAT->to_char(컬럼,'YYYY: 년, MM: 월, DD: 일, HH24: 24시간, HH: 12시간, MI: 분, SS:초') 
SELECT member_id, member_name, gender, to_char(date_of_birth, 'yyyy-MM-dd') date_of_birth
from member_profile
where tlno is not null and gender ='W' and to_char(date_of_birth, 'mm') = '03'
order by member_id;

--ifnull->nvl, nvl2 
SELECT PT_NAME, PT_NO, GEND_CD, AGE, NVL(TLNO,'NONE') AS TLNO FROM PATIENT
WHERE AGE <= 12 AND GEND_CD='W' ORDER BY AGE DESC, PT_NAME ASC
--oracle은 문자열 비교시 대소문자 구분
--group by 절에 select 컬럼 중 집계부분을 제외한 컬럼을 모두 포함시켜줘야함
--join 명시해주어야함(sql은 컬럼 연결로 생략가능했음)

--limit->rownum이용 (order by하면 rownum이 바껴서 where절에 subquery해야함) 
select * from
(SELECT NAME FROM ANIMAL_INS ORDER BY DATETIME)
where rownum=1

--to_number (문자열 숫자 정렬시 필요)
SELECT to_number(to_char(datetime, 'hh24')) as hour, count(*) as count
from animal_outs
where to_number(to_char(datetime, 'hh24')) between 9 and 19
group by to_number(to_char(datetime, 'hh24'))
order by hour

이문제들 풀면서 변수,반복, case when 추후 정리 필요
https://school.programmers.co.kr/learn/courses/30/lessons/59413
https://school.programmers.co.kr/learn/courses/30/lessons/131530

to_char 정리

https://gent.tistory.com/331

profile
studying

0개의 댓글