DELIMITER $ CREATEDEFINER 'root' @ 'localhost' FUNCTION 'uf _ Get _...
DELIMITER $ create definer = 'root' @ 'localhost' FUNCTION 'uf _ get_tmaxcode' (V_iType INT) RETURNS varchar (10) CHARSET utf8 BEGIN/* Business Description: generate encoding according to encoding type input parameter: V_iType: encoding type, define the definition of the iType field of tMaxCode call example: SELECT UF_Get_tMaxCode (1); creation date: creator: */DECLARE iCode INT; IF V_iType IN (1, 3) THEN # Non-Order class 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 class 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 select ifnull (iMax, 0) + 1 INTO iCode FROM tMaxCode WHERE iType = V_iType; else set iCode = 1; end if; if exists (SELECT iMax FROM tMaxCode WHERE iType = V_iType LIMIT 0, 1) then update tMaxCode SET iMax = iCode, dtLast = CURRENT_DATE WHERE iType = V_iType; else insert into tMaxCode (iType, iMax, dtLast) SELECT V_iType, iCode, CURRENT_DATE; end if; IF V_iType IN (0000) THEN # Non-Order class code return concat ('', iCode); ELSE # Order class code IF iCode BETWEEN 1 AND 9 then return concat ('20140901 ', iCode); ELSEIF iCode BETWEEN 10 AND 99 then return concat ('000', iCode); ELSEIF iCode BETWEEN 100 AND 999 then return concat ('00', iCode ); ELSEIF iCode BETWEEN 1000 AND 9999 then return concat ('0', iCode); ELSE // open source code phprm.com return concat ('', iCode); end if; END $ DELIMITER;
Article address:
Reprint at will ^ please include the address of this article!