create table newbook as select * from book
book 테이블의 레코드를 모두 조회하여 동일한 컬럼과 레코드를 갖는 테이블 생성
create table newbook as select * from book where 1=2;
절대로 만족하지 않는 조건을 주면 레코드는 추가하지 않고 구조만 복사할 수 있다.
update customer
set address = (select address from customer where name='김연아')
where name = '박세리';
delete orders
where custId = (select custId from customer where name = '박지성');
select workerId, substr(jumin,1,8) jumin, substr(email,1, instr(email, '@') -1) id
from worker where jumin is not null;
select lpad('hello', 10, '*') from dual;
select
w.workerId 사원번호,
w.name 사원이름,
m.name 관리자명,
lpad(round((w.salary + NVL(w.comm, 0) * 12 * 2.0), -1), 10, '0') 상여금,
rpad(substr(w.jumin,1,8), 14, '*') 주민번호,
substr(w.email, 1, instr(w.email, '@') -1) 아이디,
w.hiredate 입사일
from worker w
join worker m on w.mgr = m.id
where substr(w.jumin,8,1) in (1,3) and w.hiredate < '2021/01/01';
오늘 날짜와 시간을 알려줌
select to_char(sysdate, 'yy') from dual;
select to_char(sysdate, 'yyyy/mm/dd/hh/mi/ss') from dual;
// 나이가 27살 이상인 모든 직원의 정보
select * from worker
where workerId in (
select workerId
from (
select
workerId,
to_char(sysdate, 'yyyy')
- case
when substr(jumin, 8, 1) in ('1', '2') then concat('19',substr(jumin, 1, 2))
when substr(jumin, 8, 1) in ('3', '4') then concat('20',substr(jumin, 1, 2))
end
as age
from worker where jumin is not null
)
where age >= 27
);