MySQL fundamentals (03): summary of system and custom functions, detailed use of triggers
Source code of this article: GitHub click here | | GitEE click here |
I. the system encapsulates the function
MySQL has many built-in functions that can quickly solve some business requirements in development, including process control functions, numeric functions, string functions, date-time functions, aggregate functions, and so on. The functions commonly used in these classifications are listed below.
1. Control flow function case...when
The return value is judged according to the value, and the IF-ELSE judgment in analogical programming.
-- DEMO 01SELECT CASE DATE_FORMAT (NOW (),'% Ymuri% mmi% d') WHEN '2019-12-29' THEN 'today' WHEN' 2019-12-28 'THEN' yesterday' WHEN '2019-12-30' THEN 'tommor' ELSE' Unknow' END;-- DEMO 02SELECT (CASE WHEN 1 > 0 THEN 'true' ELSE' false' END) AS result;if (expr1,expr2,expr3)
If the expression expr1 is TRUE, the return value of IF () is expr2;, otherwise the return value is expr3.
SELECT IF (1 > 2)