MySQL과 다른 부분만 정리 중!
그 외 SQL 문법은 [DB] MYSQL 문법 참고
select concat('문자열', '합치기') from test //문자열합치기
select '010' || '-' || '0000' || '-' || '0000' from test //010-0000-0000
select left("thisistest", 2, 3) from dual; //his
select *
from (
select *
from emp
order by ename
)
where rownum = 1nvl('값', '지정값')
nvl(name, 'eunhye') //name이 null이면 "eunhye"로 지정
to_char(sysdate, 'yyyy-mm-dd hh24:mi:ss') //2023-02-24 10:00:34
to_char(sysdate, 'yyyymmdd') //20230224
to_date('2023-02-24', 'yyyy-mm-dd')
select sysdate - to_date('20230201', 'YYYYMMDD')
select * from student group by name //불가능
select name from student group by name //가능
select * from a A join b B on A.id=B.idselect *
from a A, b B
where A.id = B.id
//left outer join
select *
from a A, b B
where A.id = B.id(+)
//right outer join
select *
from a A, b B
where A.id(+) = B.id
select *
from a A, b B
merge
into a A //테이블, 뷰
using b B //테이블, 뷰, 서브쿼리
on (A.id=B.id) //조건절
when matched then //일치하는 경우 → update, delete (where 사용 가능)
update set A.name = B.name
delete
when not matched then //일치하지 않는 경우 → insert
insert (A.name, A.age)
values (B.name, B.age);
merge
into a A
using dual
on age = 20
when matched then
update set grade=1
when not matched then
insert (A.name, A.age, A.grade)
values ('Anna', 20, 1);
SELECT
LEVEL,
DEPT_NM,
LPAD(' ', 2*LEVEL-1) || SYS_CONNECT_BY_PATH(DEPT_NM, '/') PATH,
DEPT_CD,
PAR_DEPT_CD
FROM TB_DEPT
START WITH PAR_DEPT_CD IS NULL
CONNECT BY PAR_DEPT_CD = PRIOR DEPT_CD
ORDER SIBLINGS BY DEPT_CD;


select --+parallel(test, 4)
from test;
select /*parallel(test, 4)*/ from test;
select --+parallel(test, 4) full(test)
from test;
select /*parallel(test, 4) full(test)*/ from test;
nvl(name, 'No name')
select stuName as "name" from student