标签:inno cycle efi UNC end ora insert uri innodb
oracle创建序列化:
CREATE SEQUENCE flowjobseq --序列名
INCREMENT BY 1 -- 每次加几个
START WITH 6000 -- 从1开始计数
NOMAXVALUE -- 不设置最大值
NOCYCLE -- 一直累加,不循环
CACHE 10;
mysql创建序列化:
创建--Sequence 管理表
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
LANGUAGE SQL
DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT ‘‘
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
LANGUAGE SQL
DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT ‘‘
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
LANGUAGE SQL
DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT ‘‘
BEGIN
UPDATE sequence
SET current_value = value
WHERE name = seq_name;
RETURN currval(seq_name);
END
$
DELIMITER ;
先创建上面的四步,在进行创建序列化名称等。
INSERT INTO sequence VALUES (‘weituodSeq‘, 0, 1);----添加一个sequence名称和初始值,以及自增幅度
SELECT SETVAL(‘weituodSeq‘, 0);---设置指定sequence的初始值
SELECT CURRVAL(‘weituodSeq‘);--查询指定sequence的当前值
SELECT NEXTVAL(‘weituodSeq‘);--查询指定sequence的下一个值
标签:inno cycle efi UNC end ora insert uri innodb
原文地址:https://www.cnblogs.com/xiaozhouyuxiaohou/p/9128233.html