MysqlMySqlDump database backup code

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.