日期:2014-05-16 浏览次数:20702 次
DELIMITER // CREATE PROCEDURE gennid () BEGIN DECLARE st VARCHAR(100); START TRANSACTION; IF NOT EXISTS (SELECT 1 FROM order_key) THEN SET @sqlstr=CONCAT('insert into order_key select substring(`key`,8) from order', DATE_FORMAT(CURDATE(), '%Y%m'), ' order by id desc limit 1'); PREPARE st FROM @sqlstr; EXECUTE st; ELSE UPDATE order_key SET id=id+1; END IF; SELECT id INTO @iid FROM order_key; COMMIT; END //