DECLARE v_cnt INT;
DECLARE v_timestr INT;
DECLARE rowcount BIGINT;
SET v_timestr =DATE_FORMAT(NOW(),’%Y%m%d’);
SELECT ROUND(RAND()*100,0)+1 INTO v_cnt;
START TRANSACTION;
UPDATE order_seq SET order_sn+v_cnt WHERE timestr=v_timestr;
IF ROW_COUNT()=0 THEN
INSERT INTO order_seq(timestr,order_sn)VALUE(v_cnt,v_timestr);
END IF
SELECT CONCAT(v_timestr,LPAD(order_sn,7,0)) AS order_sn
FROM order_seq WHERE timestr=v_timestr;
COMMIT;
——《慕课网SQL开发技巧》
生成特殊序列号的动态存储sql
最新推荐文章于 2024-08-30 11:01:42 发布