There are many useful functions in MySQL, while basic functions can be divided into string functions, date and time functions, mathematical functions, and system functions. The following are examples of these basic functions.
One, the string function
-- mysql string function --select instr (' i am a student. ', ' student '); -- Returns the starting position of a specified string in another string ———— 8select length (' mysql '); -- returns the string length ———— 5select lower (' mysql '); -- convert the uppercase letter of the string to lowercase ———— mysqlselect upper (' MySQL '); -- Convert lowercase letters of strings to uppercase letters ———— mysqlselect ltrim (' MySQL '); -- clear the space to the left of the string ———— mysql ———— select rtrim (' MySQL '); -- clear the space to the right of the string ———— mysql ———— select Right (' I'm learning the MySQL function ', 2); -- returns the specified number of characters from the left of the string ———— function select replace (' hehe ', ' ha ', ' hee '); -- replace characters in strings ———— hee hee select insert (' ABCDEF ', 2, 3, ' La giggle '); -- Represents replacing the first string of three characters from the second position with the second string ———— a la giggle EF
Second, date and time functions
--MySQL Date function and time function--select curdate (); --Return to today's date ———— 2016-04-29select current_date (); --Return to today's date ———— 2016-04-29select curtime (); --Returns the current time ———— 11:38:13select current_time (); --Returns the current time ———— 11:38:13select current_timestamp (); --Returns the current date and time ———— 2016-04-29 11:38:41select datediff (' 2016/4/29 ', ' 2016/4/2 '); --Returns the number of days separated by two dates ———— 27select adddate (' 2016-02-29 ', 3); --Return a date a few days after a date ———— 2016-03-03select dayname (' 2016-04-29 '); -Returns a date corresponding to the day of the week ———— Fridayselect extract (days from ' 2016-04-09 '); --Returns a date ———— 9
Three, mathematical functions
-- mysql mathematical function --select abs ( -4.5); -- for absolute value ———— 4.5select ceiling (90.3); -- returns the smallest integer greater than or equal to the given number ———— 91select floor (90.7); -- returns the largest integer less than or equal to the given number ———— 90select power (2,3); -- returns the power value of an expression ———— 8select round (3.1456,2); -- Rounding The representation specifies the precision ———— 3.15select sign ( -32); -- for positive returns 1 for negative returns-1 for 0 to return 0 - ——— -1select sqrt (16.89); -- take the square root of the floating-point expression ———— 4.109744517606903select rand () ; -- random number Select convert (1231, char (3)); -- data type conversion, character type, with parameter : char () ———— 123select convert (1231,date); -- data type conversion, date DATE ———— 2000-12-31select convert (1231,time); -- data type conversion, time TIME ———— 00:12:31select Convert (20160429,datetime); -- data type conversion, date time DATETIME ———— 2016-04-29 00:00:00select convert (1231.8090,signed); -- data type conversion, integer type signed, auto rounding ———— 1232select convert ( -12,unsigned); -- data type conversion, unsigned UNSIGNED ———— 18446744073709551604
Iv. system functions
--MySQL system function--Select CharSet (' 5 reply. 9 '); --the character set that returns the string ———— Utf8select version (); --Returns the version number of the database ———— 5.6.24-logselect connection_id (); --Returns the number of connections to the server ———— 3select user (); --Returns the name of the current user ———— [email protected]select system_user (); --Returns the name of the current user ———— [email protected]select current_user (); --Returns the name of the current user ———— [email protected]select database (); --Returns the current database name ———— Student_databaseselect collation (' fjsjf898 separate with 9fs '); --Returns the character arrangement of the word a ———— utf8_general_ci
This article is from the "hualiued" blog, make sure to keep this source http://11520677.blog.51cto.com/11510677/1768994
MySQL Basic functions