mysql 模拟oracle中的序列
因业务需要,把oracle 数据据转成mysql,同时oracle中程序本来一直在用 序列,
mysql中没有,所以需要在mysql中新建一个表进行模拟,
CREATE TABLE `sequence` (
`name` varchar(200) NOT NULL,
`current_value` bigint(20) NOT NULL,
`increment` int(11) NOT NULL DEFAULT '1',
PRIMARY KEY (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `sequence` VALUES ('SEQ_UKEY_INFO', '2', '1');
create function currval(v_seq_name VARCHAR(50))
returns integer
begin
declare value integer;
set value = 0;
select current_value into value from sequence where name = v_seq_name;
return value;
end;
create function seq (seq_name VARCHAR(50))
returns integer
begin
update sequence set current_value = current_value + increment where name = seq_name;
return currval(seq_name);
end;
用函数 seq('SEQ_UKEY_INFO'),代替oracle中查询序列的函数