update
--update: 수정
--update 테이블명 set 컬럼명1='바꿀내용', 컬럼명='바꿀내용' where 조건
--직업과 나이 수정하기..where조건 안 쓰면 전체 데이터 수정됨
update person set job='공무원',age=38;
--잘못 수정한 데이터 되돌리기
rollback;
--5번의 직업과 나이 수정하기
update person set job='공무원',age=38 where num=5;
--전체 데이터 확인
select * from person;
--저장
commit;
--황씨이면서 세무사인 사람의 gender를 남자로 수정
update person set gender='남자' where name like '황%' and job='세무사';
--num이 12인 사람의 직업을 프로그래머, 입사일을 2015-10-10로 수정
update person set job='프로그래머',ipsaday='2015-10-10' where num=12;
~~~~~~~~~~~~~~~~~~~~~~~~~~
delete
--Delete_삭제
--delete from 테이블명 where 조건
--delete from 테이블명 .. 이렇게 하면 전체삭제
--person2로 삭제
--num이 5번인 사람 삭제
delete from person2 where num=5;
select * from person2;
--여자 중에서 나이가 30세 이상은 모두 삭제하기
delete from person2 where age>=30 and gender='여자';
--7번이면서 핸드폰 끝자리가 6666인 사람의 나이를 49, 입사일을 2017-07-07로 수정
update person2 set age='49', ipsaday='2017-07-07' where num='7' and hp like '_%6666';
--직업이 교사이거나 개그맨인 사람 삭제
delete from person2 where job='교사' or job='개그맨';
----컬럼을 추가..주소 addr 30바이트로 추가
alter table person2 add addr varchar2(30);
--컬럼명 변경 hp를 handphone
alter table person2 rename column hp to handphone;
--데이터 insert num,name,gender,addr만 내용 추가
insert into person2(num,name,gender,addr)values(seq1.nextval,'이현','여자','서울시 종로구');
--age가 null인 사람 출력
select * from person2 where age is null;
--handphone이 null이 아닌 사람 출력
select * from person2 where handphone is not null;
--null일 경우 정해진 값으로 출력할 경우 NVL 사용
--같은 자료형으로는 변경 가능
select name,NVL(job,'무직'),NVL(age,10) from person2;
--null일 경우 NVL로 빈칸,****로 변경
select name,NVL(job,' '),NVL(handphone,'*****') hp from person2;
drop table person2; --person2 삭제
'Oracle' 카테고리의 다른 글
210901_숫자함수 (0) | 2021.09.01 |
---|---|
210901_rollup,cube (0) | 2021.09.01 |
210831_서브쿼리 (0) | 2021.08.31 |
210831_to char (0) | 2021.08.31 |
210831_그룹함수 (0) | 2021.08.31 |