DELIMITER $$
USE `test`$$
DROP TRIGGER /*!50032 IF EXISTS */ `setSeqCustomVal`$$
CREATE
/*!50017 DEFINER = ‘root’@’localhost’ */
TRIGGER `setSeqCustomVal` BEFORE INSERT ON `worklist`
FOR EACH ROW BEGIN
DECLARE dateStr VARCHAR(12) CHARACTER SET gbk;
SET dateStr = DATE_FORMAT(NOW(), ‘%Y%m%d’);
SET @maxCode = (SELECT MAX(listCode) FROM worklist WHERE listCode LIKE CONCAT(dateStr, ‘%’));
IF @maxCode IS NULL
THEN
SET new.listCode = CONCAT(dateStr, ‘0001’);
ELSE
SET new.listCode = CAST(@maxCode + 1 AS CHAR);
END IF;
END;
$$
DELIMITER ;