mysql tutorial MySqlDump database tutorial backup code
DELIMITER $$
CREATE DEFINER=`root`@`localhost` FUNCTION `UF_Get_tMaxCode`(
V_iType INT
) RETURNS varchar(10) CHARSET utf8
BEGIN
/*
Business description: Generate codes based on coding categoriesInput parameters:
V_iType: encoding category, defines the definition of the iType field of tMaxCodeCall example:
SELECT UF_Get_tMaxCode(1);Creation date:
Created by:*/
DECLARE iCode INT;IF V_iType IN (1,3)
THEN
#Non-order type
IF EXISTS (SELECT dtLast FROM tMaxCode WHERE iType=V_iType LIMIT 0,1)
THEN
SELECT IFNULL(iMax,0)+1 INTO iCode FROM tMaxCode WHERE iType=V_iType;
ELSE
SET iCode=1;
END IF;
SELECT IFNULL(iMax,0)+1 INTO iCode FROM tMaxCode WHERE iType=V_iType;
ELSE
#Order type
IF EXISTS (SELECT iMax FROM tMaxCode WHERE iType=V_iType AND DATEDIFF(dtLast,CURRENT_DATE)=0 LIMIT 0,1)
THEN
#The last generation time was today
SELECT IFNULL(iMax,0)+1 INTO iCode FROM tMaxCode WHERE iType=V_iType;
ELSE
SET iCode=1;
END IF;
END IF;
1 2