ORACLE SEQUENCE是用于生成唯一序列值的對象。它可以在表的列中自動生成唯一的值,通常用作主鍵字段。以下是ORACLE SEQUENCE的常見用法:
CREATE SEQUENCE seq_employee_id
START WITH 1
INCREMENT BY 1
NOCACHE;
INSERT INTO employee (id, name, age)
VALUES (seq_employee_id.NEXTVAL, 'John Doe', 30);
SELECT seq_employee_id.CURRVAL
FROM dual;
ALTER SEQUENCE seq_employee_id
INCREMENT BY -1
MINVALUE 0;
CREATE TABLE employee (
id NUMBER DEFAULT seq_employee_id.NEXTVAL,
name VARCHAR2(50),
age NUMBER
);
這些是ORACLE SEQUENCE的常見用法,可以根據具體需求靈活應用。注意,在使用SEQUENCE之前,需要先創建SEQUENCE對象。