模拟oracle中sequence实现
新建查询
1、创建表tb_sequence,用来存放sequence值:
create table tb_sequence(name varchar(50) not null,current_value int not null,_increment int not null default 1, primary key(name));
2、手动插入数据:
insert into tb_sequence values('userid',100,2);
3、定义函数 _nextval:
create function _nextval(n varchar(50)) returns integer
begin
declare _cur int;
set _cur=(select current_value from tb_sequence where name= n);
update tb_sequence
set current_value = _cur + _increment
where name=n ;
return _cur;
end;
4、检验结果
select _nextval(‘userid’);
mybatis调用形式:
statementType=”CALLABLE”定义为函数调用,mode=IN为输入,mode=OUT为输出结果
{
#{p2,mode=OUT,jdbcType=NUMERIC}=call fun_add(
#{p1,mo