mysql创建序列表,根据每日日期和该序列生成单号
1.创建序列表
DROP TABLE IF EXISTS guns_sys_sequence
;
CREATE TABLE guns_sys_sequence
(
seq_name
varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT ‘序列名’,
current_val
bigint NOT NULL COMMENT ‘序列值’,
increment_val
bigint NOT NULL DEFAULT 1 COMMENT ‘每次递增跨度’,
PRIMARY KEY (seq_name
) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = ‘序列’ ROW_FORMAT = Dynamic;
2.创建存储过程
1)currval–当前值
CREATE FUNCTION currval
(v_seq_name VARCHAR(50)) RETURNS int
READS SQL DATA
DETERMINISTIC
BEGIN
DECLARE VALUE INTEGER;
SET VALUE = 0;
SELECT current_val INTO VALUE FROM guns_sys_sequence WHERE seq_name = v_seq_name;
RETURN VALUE;
END</