概述
drop PROCEDURE if EXISTS getSequence;
drop TABLE if EXISTS tb_sequence;
create PROCEDURE getSequence(in nus BIGINT)
begin
DECLARE seqid BIGINT DEFAULT 0;
DECLARE datet VARCHAR(50) DEFAULT '';
create table if not EXISTS tb_sequence(
`id` bigint(20) NOT NULL,
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`sequence` bigint(20) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`, `sequence`) USING BTREE
);
select sequence into seqid from tb_sequence where name='sequencename';
if seqid=0 then
insert into tb_sequence(id,name,sequence)values(1,'sequencename',0);
end if;
update tb_sequence set sequence=sequence+1 where name='sequencename';
select sequence into seqid from tb_sequence where name='sequencename';
select date_format(now(),'%Y%m%d%H%i%S') INTO datet;
if nus=1 then
select CONCAT(datet,'-',seqid) as seqnum;
else
select CONCAT(datet,'',seqid) as seqnum;
end if;
END;
调用
@Select("call getSequence(#{‘param’)")
————————————————
版权声明:本文为CSDN博主「初七酒~落花雨」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/yw_yiyi/article/details/117746980
最后
以上就是细腻糖豆为你收集整理的编号唯一mysql脚本的全部内容,希望文章能够帮你解决编号唯一mysql脚本所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复