1、创建序列表
CREATE TABLE IF NOT EXISTS `sequence` (
`name` VARCHAR ( 50 ) NOT NULL,
`current_value` INT ( 11 ) NOT NULL,
`increment` INT ( 11 ) NOT NULL DEFAULT '1'
)
ENGINE = InnoDB
DEFAULT CHARSET = utf8
CHECKSUM = 1
DELAY_KEY_WRITE = 1
ROW_FORMAT = DYNAMIC
COMMENT = '序列表';
2、创建序列函数
2.1、清除同名函数(不推荐直接使用)
DROP FUNCTION IF EXISTS `currval`;
2.2、新建函数(获取当前值)
CREATE FUNCTION `currval` ( seq_name VARCHAR ( 50 ) ) RETURNS INT ( 11 ) READS SQL DATA DETERMINISTIC
BEGIN
DECLARE VALUE INTEGER;
SET VALUE = 0;
SELECT current_value INTO VALUE FROM sequence WHERE NAME = seq_name;
RETURN VALUE;
<