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;

你可能感兴趣的:(oracle,sql,cache)