시퀀스란
Nextval
Currval
--시퀀스
create SEQUENCE c_country_id
INCREMENT BY 1
start with 23
maxvalue 999999
NOCACHE
nocycle;
select MAX(country_id)+1 from country;
--start with에 적을 숫자 구하는 법
insert into country(country_id,country_name,continent,capital)
values(c_country_id.nextval,'홍콩','아시아','홍콩');
--c_country_id가 23으로 됨
insert into country(country_id,country_name,continent,capital)
values(c_country_id.nextval,'조지아','유럽','트빌리시');
--c_country_id가 24로 됨
insert into city(city_id,city_name,country_id)
values(11,'쿠타이시',c_country_id.currval);
--currval 방금 생성한 24를 의미 24를 참조함
select *
from user_sequences; --현재 유저가 소유한 모든 시퀀스 정보 출력
select sequence_name,min_value, max_value,increment_by,last_number
from user_sequences;
drop SEQUENCE c_country_id; --시퀀스 삭제