oracle 唯一键sequence、触发器

 



-- Create sequence
create sequence S_表名
minvalue 1
maxvalue 999999999999999999999999999
start with 1
increment by 1
cache 20;

CREATE OR REPLACE TRIGGER "触发器名"
BEFORE INSERT OR UPDATE ON 表名
REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW
BEGIN
IF INSERTING THEN
SELECT S_表名.NEXTVAL INTO :NEW.ID FROM DUAL; -- ID 表字段ID
END IF;

:NEW.UPDATE_TIME := TO_CHAR(SYSDATE,'YYYY-MM-DD HH24:MI:SS'); -- UPDATE_TIME 更新日期
END;

 

posted on 2022-08-18 15:52  花非花-雾非雾  阅读(48)  评论(0编辑  收藏  举报