本节内容:
Oracle序列与触发器
1,创建序列(为触发器提供服务)
复制代码 代码示例:
create sequence SEQ_USER
minvalue 1
maxvalue 9999999999999999999999999999
start with 1
increment by 1
cache 20;
2,创建触发器
复制代码 代码示例:
CREATE OR REPLACE TRIGGER TRI_USER BEFORE
INSERT ON USER FOR EACH ROW
DECLARE
V_ID NUMBER;
BEGIN
SELECT SEQ_USER.NEXTVAL INTO V_ID FROM DUAL;
:NEW.ID := LPAD(V_ID,5,'0');
END TRI_USER;