'오라클시퀀스'에 해당되는 글 1건

  1. 2017.03.17 oracle sequence 생성,조회

oracle sequence 생성,조회



생성 옵션값에 대해 알아보자.

CREATE SEQUENCE 시퀀스명

START WITH n[초기화 값]

INCREMENT BY n[증가값]

MAXVALUE n[최대값]  또는 NOMAXVALUE  [무한대값]

MINVALUE n [최소값]  또는 NOMINVALUE [무한대값]



그럼 생성해보자

시퀀스명 = test_seq 

초기값 = 1

증가값 = 1

최대값 = 500


create sequence test_seq 

start with 1 

increment BY 1

maxvalue 10000


생성된 test_seq 사용하는 방법

insert into test (id_seq, name )

values(test_seq.nextval, 'HI' );


insert문 실행후 최종(현재) 시퀀스값 조회

select 시퀀스명.currval from dual;


insert문 실행 없이 최종 시퀀스값 조회

select * from user_sequences

where sequence_name=upper('시퀀스명')


결과 데이터에서 last_number 가 현재 시퀀스값을 의미함.

시퀀스 초기화 할시 현재 시퀀스를 삭제후 다시 생성해야함.





'DB > ORACLE' 카테고리의 다른 글

ROLLUP - 소계,합계 구하기  (0) 2017.05.19
oracle index  (0) 2017.01.19
PIVOT 사용  (0) 2017.01.03
ALTER TABLE  (0) 2016.11.28
Posted by 양승아
: