1 use a sequence and a trigger:--create a sequence
CREATE SEQUENCE sequencename INCREMENT BY 1 START WITH 1 MAXVALUE 999999999;--create a trigger ( before insert ) base on the table,and use the sequence in itCREATE OR REPLACE TRIGGER triggername
BEFORE INSERT ON on tablename
REFERENCING old AS old new as new for each row
BEGIN
SELECT sequencename.nextval into :new.fieldname(the filed that you want it to autoadd) FROM dual;
END;
/2 use a trigger directly:CREATE OR REPLACE TRIGGER triggername
BEFORE INSERT ON tablename
FOR EACH ROWDECLARE
variablename NUMBER;BEGIN
SELECT MAX(fieldname) INTO variablename FROM tablename;
:NEW.fieldname:=variablename+1;
END;
/
CREATE SEQUENCE sequencename INCREMENT BY 1 START WITH 1 MAXVALUE 999999999;--create a trigger ( before insert ) base on the table,and use the sequence in itCREATE OR REPLACE TRIGGER triggername
BEFORE INSERT ON on tablename
REFERENCING old AS old new as new for each row
BEGIN
SELECT sequencename.nextval into :new.fieldname(the filed that you want it to autoadd) FROM dual;
END;
/2 use a trigger directly:CREATE OR REPLACE TRIGGER triggername
BEFORE INSERT ON tablename
FOR EACH ROWDECLARE
variablename NUMBER;BEGIN
SELECT MAX(fieldname) INTO variablename FROM tablename;
:NEW.fieldname:=variablename+1;
END;
/
--create a sequence
CREATE SEQUENCE sequencename INCREMENT BY 1 START WITH 1 MAXVALUE 999999999;--create a trigger ( before insert ) base on the table,and use the sequence in itCREATE OR REPLACE TRIGGER triggername
BEFORE INSERT ON on tablename
REFERENCING old AS old new as new for each row
BEGIN
SELECT sequencename.nextval into :new.fieldname(the filed that you want it to autoadd) FROM dual;
END;
/
2 use trigger directly:
CREATE OR REPLACE TRIGGER triggername
BEFORE INSERT ON tablename
FOR EACH ROWDECLARE
variablename NUMBER;BEGIN
SELECT MAX(fieldname) INTO variablename FROM tablename;
:NEW.fieldname:=variablename+1;
END;
/
--create a sequence
CREATE SEQUENCE sequencename INCREMENT BY 1 START WITH 1 MAXVALUE 999999999;--create a trigger ( before insert ) base on the table,and use the sequence in itCREATE OR REPLACE TRIGGER triggername
BEFORE INSERT ON on tablename
REFERENCING old AS old new as new for each row
BEGIN
SELECT sequencename.nextval into :new.fieldname(the filed that you want it to autoadd) FROM dual;
END;
/
2 use a trigger directly:
CREATE OR REPLACE TRIGGER triggername
BEFORE INSERT ON tablename
FOR EACH ROWDECLARE
variablename NUMBER;BEGIN
SELECT MAX(fieldname) INTO variablename FROM tablename;
:NEW.fieldname:=variablename+1;
END;
/
create sequence seq_name
minvalue 1
maxvalue 99999999999999999999999
increment by 1
start with 1;
然后,在向表中插入数据的时候,取得sequence的next伪列的值,作为该字段的值进行插入;insert myTable values (seq_name.next(),other,columns);