使用序列和触发器实现oracle数据库的id自增,插入数据随便输入其他该id数据类型的值会自动调整到自增id,但在values内使用seq_id.nextval作为id插入数据,为什么会增2?
-- 插入语句
INSERT INTO LWC VALUES (1,'李四');
INSERT into LWC VALUES (100,'张三');
INSERT into LWC VALUES (102,'张5');
INSERT into LWC VALUES (seq_lwc_id.nextval,'dd');
INSERT into LWC VALUES (seq_lwc_id.nextval,'aa');
INSERT into LWC VALUES (seq_lwc_id.nextval,'bb');
INSERT into LWC VALUES (seq_lwc_id.nextval,'cc');
INSERT INTO LWC VALUES (seq_lwc_id.val,'dasd');
-- 创建序列和触发器语句
create sequence seq_lwc_id
minvalue 1
maxvalue 99999999999
start with 1
increment by 1
nocache;
CREATE OR REPLACE TRIGGER lwc_id_tri
before INSERT ON LWC
FOR each ROW
BEGIN
select seq_lwc_id.nextval into :new.id from dual;
END;
/
运行结果及报错内容