ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 잘 참고하겠습니다~~
    RDBMS/oracle 2010. 5. 25. 21:54

    오라클에서 자동으로 증가되는 숫자를 만들어주는 객체이다.


    생성방법은


    create sequence [시퀀스명]

    start with [시작 숫자]

    increment by [증가되는 숫자]

    maxvalue n | nomaxvalue

    minvalue n | nominvalue

    cycle | nocycle


    예를 들면,

    create sequence seq_board

    start with 1

    increment by 1

    maxvalue 100000000

    ;


    그리고 board라는 테이블에 insert 할 때는

    insert table board(num) values(seq_board.nextval);


    요렇게 하면, insert 할때 자동으로 1씩 증가하여 num 컬럼에 삽입된다.


    [시퀀스객체명].nextval은 현재 시퀀스값에 1을 더한값

    [시퀀스객체명].currval은 현재 시퀀스값


    참고로 오라클에서 시퀀스의 값을 알고싶으면..


    select seq_board.currval from dual;


    삭제는

    drop sequence seq_board;


    시퀀스는 alter나 update가 안된다는 사실..

    즉 수정불가..

    잘못되면 무조건 삭제.. all or nothing! 이거 맞나?

    시퀀스 객체는 생성하면 여러테이블에서 사용할 수 있다

    댓글

Designed by Tistory.