CREATE SEQUENCE TEST_EQ
START WITH 1
INCREMENT BY 1;
SELECT TEST_EQ.NEXTVAL
FROM DUAL;
SELECT TEST_EQ.CURRVAL
FROM DUAL;
DROP SEQUENCE TEST_EQ;
DROP TABLE emp01 PURGE;
CREATE TABLE emp01(
empno NUMBER(4) CONSTRAINT PK_SEQ_EMPNO PRIMARY KEY,
ename VARCHAR2(10),
hiredate DATE
);
DESC emp01;
CREATE SEQUENCE emp01_empno_seq
START WITH 1
INCREMENT BY 1
MAXVALUE 1000;
INSERT INTO emp01 VALUES (emp01_empno_seq.nextval, 'man_a', SYSDATE);
INSERT INTO emp01 VALUES (emp01_empno_seq.nextval, 'man_b', SYSDATE);
SELECT * FROM emp01;
DROP SEQUENCE emp01_empno_seq;
CREATE TABLE SEQTEST(
sno NUMBER(2) PRIMARY KEY
);
DESC SEQTEST;
INSERT INTO SEQTEST VALUES (SEQTEST_SEQ.NEXTVAL);
INSERT INTO SEQTEST VALUES (SEQTEST_SEQ.NEXTVAL);
INSERT INTO SEQTEST VALUES (SEQTEST_SEQ.NEXTVAL);
SELECT * FROM SEQTEST;
-- INSERT INTO SEQTEST VALUES (SEQTEST_SEQ.NEXTVAL); error
ALTER SEQUENCE SEQTEST_SEQ
MAXVALUE 10;
INSERT INTO SEQTEST VALUES (SEQTEST_SEQ.NEXTVAL);
SELECT * FROM SEQTEST;
DROP TABLE SEQTEST PURGE;
DROP SEQUENCE SEQTEST_SEQ;
CREATE TABLE QDEPT(
deptno NUMBER(2) PRIMARY KEY,
dname VARCHAR2(20),
loc VARCHAR2(20)
);
DESC QDEPT;
CREATE SEQUENCE QDEPT_DEPTNO_SEQ
START WITH 10
INCREMENT BY 10
NOCACHE NOCYCLE;
INSERT INTO QDEPT VALUES (QDEPT_DEPTNO_SEQ.NEXTVAL, '부서-A', '지역-A');
INSERT INTO QDEPT VALUES (QDEPT_DEPTNO_SEQ.NEXTVAL, '부서-B', '지역-B');
INSERT INTO QDEPT VALUES (QDEPT_DEPTNO_SEQ.NEXTVAL, '부서-C', '지역-C');
SELECT * FROM QDEPT;
DROP TABLE QDEPT PURGE;
DROP SEQUENCE QDEPT_DEPTNO_SEQ;