insert into departments
values (280, 'Java', 200, 1700);
select *
from departments
order by department_id desc;
insert into departments(department_name, location_id, manager_id, department_id)
values ('Jsp', 1700, 201, 290);
select *
from departments
order by department_id desc;
![](https://velog.velcdn.com/images/tlqdnwls/post/ad9fcbd7-255d-449f-bc2c-5da4cda276be/image.png)
select *
from departments
order by department_id desc;
insert into departments
values (310, 'Html', 202, null);
select *
from departments
order by department_id desc;
insert 구문 사용 후, commit 해야함
oracle은 values절 뒤에 한행씩만 추가됨
create table copy_emp
as select *
from employees
where 1=2;
desc copy_emp;
insert into copy_emp
select *
from employees;
commit;
select employee_id, salary, department_id
from employees
where employee_id = 113;
update employees
set department_id = 50
where employee_id = 113;
select employee_id, salary, department_id
from employees
where employee_id = 113;
commit
update copy_emp
set department_id = 110;
select employee_id, department_id
from copy_emp;
rollback;
select employee_id, department_id
from copy_emp;
select employee_id, last_name, job_id, salary
from copy_emp
where employee_id in (113,205);
update copy_emp
set job_id =
(select job_id
from copy_emp
where employee_id = 205),
salary =
(select salary
from copy_emp
where employee_id = 205)
where employee_id = 113;
select employee_id, last_name, job_id, salary
from copy_emp
where employee_id in (113,205);
commit;
delete from departments
where department_id = 300;
select *
from departments
order by department_id desc;
commit;
delete from copy_emp;
select *
from copy_emp;
rollback;
select *
from copy_emp;
delete from copy_emp
where department_id =
(select department_id
from departments
where location_id=1800);
select employee_id, last_name, department_id
from copy_emp
where department_id =
(select department_id
from departments
where location_id = 1800);
commit;
// 트랜잭션 시작
rollback;
// 트랜잭션 종료
// 트랜잭션 시작
create table ---; (DDL) autocommit 내포
// 트랜잭션 종료
// 트랙잭션 시작
update --;
update --;
insert --;
create table ---;(DDL) autocommit 내포
//트랜잭션 종료
// 트랜잭션 시작
delete --;
update --;
SQLPlus 또는 SQLdeveloper를 정상 종료함.
(autocommit)
// 트랜잭션 종료
// 트랜잭션 시작
delete --;
update --;
SQLPlus 또는 SQLdeveloper를 정상 종료함.
(autorollback)
// 트랜잭션 비정상 종료함
savepoint가 중간 저장하는 명령어는 아니다
트랜잭션 진행 중 되돌아 갈 수 있는 지점
select employee_id, last_name, salary, department_id
from copy_emp
where department_id = 30;
update copy_emp
set salary = salary * 1.5
where department_id = 30;
select employee_id, last_name, salary, department_id
from copy_emp
where department_id = 30;
select employee_id, last_name, salary, department_id
from copy_emp
where department_id in (30,110)
order by department_id;
update copy_emp
set salary = salary *1.2
where department_id = 110;
select employee_id, last_name, salary, department_id
from copy_emp
where department_id in (30,110)
order by department_id;
savepoint test1;
delete from copy_emp
where department_id = 50;
select employee_id, last_name, department_id
from copy_emp
where department_id = 50;
rollback to test1;
select employee_id, last_name, department_id
from copy_emp
where department_id in (30, 50, 110)
order by department_id;
commit;
sqlplus에서 시행
숫자인 경우
l로 다시 불러와 employee_id 계속 조회 가능
문자열인 경우
SQL> @/home/oracle/new_dept.sql
입력 후 저장.
불러오기 해서 실행 할 수 있음.
1번
select last_name
from employees
where lower(last_name)like '%a%e%'
or lower(last_name)like '%e%a%';
2번
select last_name, job_id, salary
from employees
where (job_id in ('SA_REP', 'ST_CLERK'))
and
(salary not in (2500, 3500, 7000));
3번
select last_name "Name", length(last_name) "Length"
from employees
where
lower(last_name) like 'j%' or
lower(last_name) like 'a%' or
lower(last_name) like 'm%'
order by last_name;
4번
select last_name "Name", length(last_name) "Length"
from employees
where lower(last_name) like lower('&START_LETTER%')
order by last_name;