自己参与的项目中遇到过,由于系统用的数据库换成了mysql,在不改变之前语法的原意上,用mysql的语法替换。
式例:
<!-- select SEQ_TB_DATA_ASSISTANT_ORDER.nextval as id from dual --> oracle
SELECT nextval('seq_test') as id -->mysql
中间需要序列号的创建:(步骤如下,亲测有效)-->序列号就相当于在数据库中创建了一个表一样,里面设置了几个字段,比如给字段A设置了一个初始值,然后开始步增,步增规则在创建序列号里设置;
1
drop table if exists sequence_assiatant_order;
CREATE TABLE sequence_assiatant_order(
sequence_id varchar(50) NOT NULL COMMENT '序列名称',
current_val int(10) not NULL COMMENT '当前值',
increment_val int(10) not NULL default 1,
PRIMARY KEY (sequence_id)) ;
2
INSERT INTO sequence VALUES ('seq_test','273','1');
2.1
create function currval( SEQ_TB_DATA_ASSISTANT_ORDER VARCHAR(50)) returns integer(11)
begin
declare value integer;
set value =273;
select current_val into value from sequence where sequence_id =SEQ_TB_DATA_ASSISTANT_ORDER ;
return value;
end;
2.2
select currval ('seq_test');
3
create function nextval( SEQ_TB_DATA_ASSISTANT_ORDER VARCHAR(50)) returns integer(11)
begin
update sequence set current_val = current_val + increment_val where sequence_id=SEQ_TB_DATA_ASSISTANT_ORDER ;
return currval(SEQ_TB_DATA_ASSISTANT_ORDER );
end;
4
select nextval('seq_test');