have been engaged in Oracle, after coming to the new company, although it feels similar to MySQL, but MySQL is still very inconvenient, such as the following functions do not support TURNC such a simple function.
A stored procedure that is intended to write an order number, similar to the letter + Month Day number
BEGIN
DECLARE currentdate VarCHAR (15);--current date, may contain time and seconds
DECLARE maxno INT DEFAULT 0; --the last 5 digits of the serial number of the order number of the nearest satisfying condition, such as: SH2013011000002 's maxno=2
SELECT Date_format (now (), '%y%m%d ') into currentdate;
Select MAX (substring (t.order_no,12,4)) into Maxno from Mmd_po_order t where substring (t.order_no,4,8) =date_format (now ( ), '%y%m%d ');
If maxno!= ' Then
SELECT CONCAT (' MMD ', currentdate, Lpad ((maxno + 1), 4, ' 0 ')) into OrderNo; --Lpad ((maxno + 1), 5, ' 0 '): if less than 5 bits, the left is filled with 0
ELSE
SELECT CONCAT (' MMD ', currentdate, ' 0001 ') into OrderNo;
END IF;
Select OrderNo;
COMMIT;
END
Initial contact for MySQL database stored procedure