Oracle 기본정리 - 시퀀스(sequence)
프로그래밍 정리/Oracle
2019. 12. 4. 13:09
반응형
Oracle 기본정리 - 시퀀스(sequence)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | --------------------------------------------------시퀀스---------------------------------------------------------- --시퀀스 생성 create sequence seq1; -- XX.nextval 시퀀스 조회할 때마다 값이 1씩 증가 select seq1.nextval from dual; --XX.currval 현재 시퀀스 값 조회 select seq1.currval from dual; --------------------------------------------------------------------- --테이블에 시퀀스 적용해보기 create table board ( no number(3) constraint board_no_pk primary key , title varchar2(20) ); create sequence se1; insert into board values(se1.nextval,'hong'); insert into board values(se1.nextval,'park'); select * from board; --삭제하고 다시 집어넣어보기 delete from board; insert into board values(se1.nextval,'haha'); select * from board; -------------------------------------------------------------- --다른테이블에서 동일한 시퀀스 사용해보기 create table board2 ( no number(3) constraint board2_no_pk primary key , name varchar2(20) ); insert into board2 values(se1.nextval,'aaa'); --시퀀스가 4부터 시작한다. select * from board2; ---------------------------------------------------- --시퀀스 시작번호 조절, 증가 값 조절 create sequence s1 start with 10 increment by 5; --10부터 시작, 5씩 증가 select s1.nextval from dual; ---------------------------------------------------- --시퀀스 최댓값, 최솟값, 사이클, cache -- 2 4 6 8 10 -10 -8 -6 -4 -2 0 2.... create sequence s2 start with 8 increment by 2 maxvalue 10 minvalue -10 cycle cache 3; select s2.nextval from dual; --시퀀스 조회 select * from user_sequences; --시퀀스 삭제 drop sequence s1; | cs |
반응형
'프로그래밍 정리 > Oracle' 카테고리의 다른 글
Oracle 기본정리 - Declare, Procedure 기본 (0) | 2019.12.04 |
---|---|
Oracle 기본정리 - 인덱스(Index) (0) | 2019.12.04 |
Oracle 기본정리 - view (0) | 2019.12.04 |
Oracle 기본정리 - 외래키, 제약조건 (0) | 2019.12.04 |
Oracle 기본정리 - recyclebin (0) | 2019.12.04 |