'sequence'에 해당되는 글 1건

  1. 2012.11.23 oracle auto_increment 구현 (sequence)

1. 전체 시퀀스 조회

select * from user_sequences;

 

2. 생성
[] 안의 내용이 업어도 생성은 됨

 

create sequence 시퀀스명
[ increment by 증가값 ]
[ start with 시작숫자 ]
[ maxvalue 최대값 ]
[ minvalue 최소값 ]
[ cycle | nocycle]
[ cache 값 | nocache ];

 

increment by : 증가, 감소(-)할 값 설정
start with : 시작할 값 설정
maxvalue : 최대값 설정
minvalue : 최소값 설정
cycle : 최소, 최대값에 다다르면 start with 값으로 되돌아감
nocycle : 최소, 최대값에 다다르면 에러가 발생
cache : 메모리상의 시퀀스 값을 관리

 

ex) 생성 예제
create sequence seq_member
increment by 1
start with 1
maxvalue 1000
minvalue 1
nocycle
cache 20;

==> 1부터 1000까지 1씩 증가하는 시퀀스 생성

 

3. 삭제
drop sequence 시퀀스명;

 

4. 수정
[] 안의 내용이 업어도 수정은 됨

※ start with 값은 수정불가

alter sequence 시퀀스명
[ increment by 증가값 ]
[ maxvalue 최대값 ]
[ minvalue 최소값 ]
[ cycle | nocycle]
[ cache 값 | nocache ];

 

각 옵션의 내용은 생성과 같다

 

5. 사용법
- 시퀀스의 다음값 알아내기

select 시퀀스명.nextval from dual;

- 시퀀스의 현재값 알아내기

select 시퀀스명.currval from dual;

ex) 입력 예제
insert into table (no, id, pw) value (시퀀스명.nextval, 'ID', 'PW');

 

'공부 > oracle' 카테고리의 다른 글

oracle pl/sql 기본구조/ 함수/ 프로시저  (0) 2012.11.23
oracle limit 기능 구현  (0) 2012.11.23
oracle 사용자 권한 설정  (0) 2012.11.23
Posted by hidden1
,