CREATE TABLE `sequence` (
`seq_name` varchar(50) NOT NULL,
`current_val` int(11) NOT NULL,
`increment_val` int(11) NOT NULL DEFAULT '1',
PRIMARY KEY (`seq_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--------------------------------------------------------------------------------------------------------------------------------------------------
CREATE DEFINER=`root`@`localhost` FUNCTION `currval`(v_seq_name VARCHAR(50)) RETURNS int(11)
begin
declare value integer;
set value = 0;
select current_val into value
from sequence
where seq_name = v_seq_name;
return value;
end
------------------------------------------------------------------------------------------------------------------------------------------------
CREATE DEFINER=`root`@`localhost` FUNCTION `nextval`(v_seq_name VARCHAR(50)) RETURNS int(11)
begin
update sequence
set current_val = current_val + increment_val
where seq_name = v_seq_name;
return currval(v_seq_name);
end
转载于:https://www.cnblogs.com/jpfss/p/9755041.html