问题
Any one help me to create a trigger for auto increment fld_id and Unix datetime. My table field is fld_id(int),fld_date(number),fld_value(varchar2).
My insert query is
insert into table (fld_value)values('xxx');
insert into table (fld_value)values('yyy');
I need the table record like this
fld_id fld_date fld_value
1 1354357476 xxx
2 1354357478 yyy
Please help me to create this.I can't able to do this..
回答1:
If you want fld_id
to be a sequential value, you'll need to create a sequence and a trigger
CREATE SEQUENCE sequence_name
START WITH 1
INCREMENT BY 1
CACHE 20;
CREATE OR REPLACE TRIGGER trigger_name
BEFORE INSERT ON table_name
FOR EACH ROW
BEGIN
SELECT sequence_name.nextval
INTO :new.fld_id
FROM dual;
:new.fld_date := (SYSDATE - date '1970-01-01') * 60 * 60 * 24;
END;
来源:https://stackoverflow.com/questions/13656520/create-trigger-for-auto-incerment-id-and-default-unix-datetime