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 

发布评论
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!

关于JDBC连接数据库时出现的Public Key Retrieval is not allowed错误知识解答
你是第一个吃螃蟹的人
发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。