Common functions are summarized in Mysql
1, character function
splicing concat: concat (str1, '_' , str2) with the str1 str2 two fields with '_' splice together
substr taken substring: substr ( 'hahaha', 3 ) = 'haha' substr ( 'hahah', 1,4) = 'haha' 4 is a longitudinal
upper uppercase: upper ( 'HAAH')
Lower converted to lower
trim to the front and rear spaces and characters specified, the default is to space, trim ( 'a', ' aahahahaca') = 'hahahac'
LTRIM spaces to the left
rtrim spaces to the right
replace ~
lpad left padding: lpad ( 'str', 10 , '*') the total length of length 10 str * not use filler
rpad right padding
instr first return substring occurrences of the index (first match) if not found returns 0
length obtaining the number of bytes (string length)
2, mathematical functions
round: rounding round (1.65) = 2 round ( 1.765,2) = 1.76 represents 2 decimal places
rand nonce
floor rounding down returns the largest integer less than or equal to the parameter
ceil ceil returns the smallest integer greater than or equal to the parameter
mod modulo mod (10,3)
truncate truncated truncate (1.69999,1) = 1.6 1 decimal point several truncated, non rounding rule
3, the date function is
now the current system date + time now ()
CURDATE CURDATE the current system date ()
curtime CURDATE current system time ()
STR_TO_DATE the specify the date format characters into the foreground came time to convert the format to date format in mysql
date_format Converts a date to a date to convert the character into a prescribed format displayed
on year (now ())
month month (now ())
months name monthname (now ())
The date and time characters:
Year% Y four of
% y two Year-bit
% m month (01,02,03, ..., 11, 12)
% c month (, 2, 3, ..., 11, 12)
% d day (01, 02, ... )
% H hour (24-hour)
% H hour (12 hour)
% I min (00, 01 ... 59)
% S second (00, 01, 59 ...)
4, the flow control function
if treatment dual branch
if (1 <2, 'I am 1', 'I 2') times eventually return statement 'I am 1'
Multiple if
case
when case1 then execute the statement 1
when case2 then executes the statement 2
when case3 then execute the statement 3
else statement to execute 4
end as a new variable
case statement to handle multiple branches
case field or expression
when case1 then execute the statement 1
when case2 then executes the statement 2
when case3 then execute the statement 3
else statement to execute 4
end as a new variable
For more, see: https://www.runoob.com/mysql/mysql-functions.html
1, character function
splicing concat: concat (str1, '_' , str2) with the str1 str2 two fields with '_' splice together
substr taken substring: substr ( 'hahaha', 3 ) = 'haha' substr ( 'hahah', 1,4) = 'haha' 4 is a longitudinal
upper uppercase: upper ( 'HAAH')
Lower converted to lower
trim to the front and rear spaces and characters specified, the default is to space, trim ( 'a', ' aahahahaca') = 'hahahac'
LTRIM spaces to the left
rtrim spaces to the right
replace ~
lpad left padding: lpad ( 'str', 10 , '*') the total length of length 10 str * not use filler
rpad right padding
instr first return substring occurrences of the index (first match) if not found returns 0
length obtaining the number of bytes (string length)
2, mathematical functions
round: rounding round (1.65) = 2 round ( 1.765,2) = 1.76 represents 2 decimal places
rand nonce
floor rounding down returns the largest integer less than or equal to the parameter
ceil ceil returns the smallest integer greater than or equal to the parameter
mod modulo mod (10,3)
truncate truncated truncate (1.69999,1) = 1.6 1 decimal point several truncated, non rounding rule
3, the date function is
now the current system date + time now ()
CURDATE CURDATE the current system date ()
curtime CURDATE current system time ()
STR_TO_DATE the specify the date format characters into the foreground came time to convert the format to date format in mysql
date_format Converts a date to a date to convert the character into a prescribed format displayed
on year (now ())
month month (now ())
months name monthname (now ())
The date and time characters:
Year% Y four of
% y two Year-bit
% m month (01,02,03, ..., 11, 12)
% c month (, 2, 3, ..., 11, 12)
% d day (01, 02, ... )
% H hour (24-hour)
% H hour (12 hour)
% I min (00, 01 ... 59)
% S second (00, 01, 59 ...)
4, the flow control function
if treatment dual branch
if (1 <2, 'I am 1', 'I 2') times eventually return statement 'I am 1'
Multiple if
case
when case1 then execute the statement 1
when case2 then executes the statement 2
when case3 then execute the statement 3
else statement to execute 4
end as a new variable
case statement to handle multiple branches
case field or expression
when case1 then execute the statement 1
when case2 then executes the statement 2
when case3 then execute the statement 3
else statement to execute 4
end as a new variable
For more, see: https://www.runoob.com/mysql/mysql-functions.html