需求生成一个单据编号
单据编号结构: “单据类型” + “日期” + “流水号”
例子 : GD201605230000007
代码:
DELIMITER $$ CREATE PROCEDURE `yunzhi`.`auto_no`()) BEGIN DECLARE v_timestr VARCHAR(); DECLARE v_cnt INT; DECLARE rowcount BIGINT; -- 当前日期(8位短日期) SET v_timestr = DATE_FORMAT(NOW(), '%Y%m%d'); SELECT CONCAT(billType,v_timestr) INTO v_timestr; ; ) WHERE timestr = v_timestr; THEN ); END IF; ,)) AS sn FROM no_seq WHERE timestr = v_timestr; COMMIT; END$$ DELIMITER ;