The code is as follows: |
Copy code |
DELIMITER $ Create definer = 'root' @ 'localhost' FUNCTION 'uf _ get_tmaxcode '( V_iType INT ) RETURNS varchar (10) CHARSET utf8 BEGIN /* Business Description: code is generated based on the encoding category. Input parameters: V_iType: specifies the encoding type and defines the iType field for tMaxCode creation. Call example: SELECT UF_Get_tMaxCode (1 ); Creation date: Created: */ 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 is the same day
Select ifnull (iMax, 0) + 1 INTO iCode FROM tMaxCode WHERE iType = V_iType;
ELSE
SET iCode = 1;
End if;
End if;