Mybatis Plus入门

2019-07-30  本文已影响0人  金石_832e

传送门
官方传送门


oracle主键自增长

-- 创建序列
create sequence SEQ_user
minvalue 1
maxvalue 99999999
start with 1
increment by 1
nocache
order;

-- 创建触发器(向tb_user表中插入记录时,id根据SEQ_user序列规则增长)
create or replace trigger tri_seq_user_id
  before insert on tb_user   
  for each row
declare
  nextid number;
begin
  IF :new.id IS NULL or :new.id=0 THEN --DepartId是列名
    select SEQ_user.nextval --SEQ_ID正是刚才创建的
    into nextid
    from sys.dual;
    :new.id:=nextid;
  end if;
end tri_seq_user_id;

-- 插入测试
insert into tb_user(name,age)values('zhangsan',28); 
-- 查询
select * from tb_user;

-- 查找下一个序列号(当新纪录插入时,ID为该SEQ_user.nextval)
select SEQ_user.nextval from sys.dual;  

https://img.haomeiwen.com/i14210893/af17899efaa0a18f?imageMogr2/auto-orient/strip|imageView2/2/format/webp

上一篇 下一篇

猜你喜欢

热点阅读