发布网友 发布时间:2022-05-05 06:07
共2个回答
懂视网 时间:2022-05-05 10:28
-- 定义序列表 DROP TABLE IF EXISTS sequence; CREATE TABLE sequence ( name VARCHAR(50) NOT NULL, current_value INT NOT NULL, increment INT NOT NULL DEFAULT 1, PRIMARY KEY (name) ) ENGINE=InnoDB; -- 获取当前序列号 DROP FUNCTION IF EXISTS currval; DELIMITER $ CREATE FUNCTION currval (seq_name VARCHAR(50)) RETURNS INTEGER CONTAINS SQL BEGIN DECLARE value INTEGER; SET value = 0; SELECT current_value INTO value FROM sequence WHERE name = seq_name; RETURN value; END$ DELIMITER ; -- 获取下一个序列号 DROP FUNCTION IF EXISTS nextval; DELIMITER $ CREATE FUNCTION nextval (seq_name VARCHAR(50)) RETURNS INTEGER CONTAINS SQL BEGIN UPDATE sequence SET current_value = current_value + increment WHERE name = seq_name; RETURN currval(seq_name); END$ DELIMITER ; -- 重设序列号 DROP FUNCTION IF EXISTS setval; DELIMITER $ CREATE FUNCTION setval (seq_name VARCHAR(50), value INTEGER) RETURNS INTEGER CONTAINS SQL BEGIN UPDATE sequence SET current_value = value WHERE name = seq_name; RETURN currval(seq_name); END$ DELIMITER ; -- 初始化数据 INSERT INTO sequence VALUES ('SAMPLE', 1, 1); -- 测试 SELECT currval('SAMPLE'); SELECT nextval('SAMPLE'); SELECT nextval('SAMPLE'); SELECT setval('SAMPLE',150); SELECT currval('SAMPLE'); SELECT nextval('SAMPLE'); SELECT nextval('SAMPLE');
热心网友 时间:2022-05-05 07:36
如果想要对查询出来的内容进行排序,并且查询的内容是中文,那么解决的办法: