1. Built-in functions 1. Mathematical functions
2. String functions length() Byte length ucase() Uppercase concat(character,...,character n) concatenates strings replace(string, old character, new character) string replacement Intercepting a string mysql> select left('123456',4); +------------------+ | left('123456',4) | +------------------+ | 1234 | +------------------+ 1 row in set (0.00 sec) mysql> select right('123456',4); +-------------------+ | right('123456',4) | +-------------------+ | 3456 | +-------------------+ 1 row in set (0.00 sec) mysql> select substring('123456',2,4); +-------------------------+ | substring('123456',2,4) | +-------------------------+ | 2345 | +-------------------------+ 1 row in set (0.00 sec) 3. Date functions
mysql> select now(); +---------------------+ | now() | +---------------------+ | 2019-03-16 14:55:42 | +---------------------+ 1 row in set (0.00 sec) mysql> select unix_timestamp(); +------------------+ | unix_timestamp() | +------------------+ |1552719356 | +------------------+ 1 row in set (0.00 sec) mysql> select from_unixtime(1552719356); +---------------------------+ | from_unixtime(1552719356) | +---------------------------+ | 2019-03-16 14:55:56 | +---------------------------+ 1 row in set (0.00 sec)
mysql> select -> year(now()) as 'year', -> month(now()) as 'month', -> day(now()) as '日', -> hour(now()) as 'hour', -> minute(now()) as '分', -> second(now()) as 'seconds'; +------+------+------+------+------+------+ | Year| Month| Day| Hour| Minute| Second| +------+------+------+------+------+------+ | 2019 | 3 | 16 | 14 | 59 | 12 | +------+------+------+------+------+------+ 4. Encryption Function md5(data) 5. Conditional judgment function 1). Syntax: if (data, value1, value2) #Judge whether the specified data is true: true - value1, false - value2 mysql> select if(null,1,2); +--------------+ | if(null,1,2) | +--------------+ | 2 | +--------------+ 1 row in set (0.00 sec) mysql> select if(1,0,2); +-----------+ | if(1,0,2) | +-----------+ | 0 | +-----------+ 1 row in set (0.00 sec) 2). Syntax: IFNULL(data, value2) #Judge whether the specified data is null: null-value2, non-null-itself mysql> select ifnull(0,123); +---------------+ | ifnull(0,123) | +---------------+ | 0 | +---------------+ 1 row in set (0.00 sec) mysql> select ifnull('a',123); +-----------------+ | ifnull('a',123) | +-----------------+ | a | +-----------------+ 1 row in set (0.00 sec) 2. Custom functions grammar: #Modify the end character delimiter // create function function name (parameter name type, ..., parameter name n type n) returns return data type begin #SQL statement return return value; end // delimiter ; #Call select function name(); Output "hello world" (function without parameters) #Judge whether the function exists, if it exists, delete it drop function if exists f1; delimiter // create function f1() returns varchar(30) begin return 'hello world'; end // delimiter ; select f1(); +-------------+ | f1() | +-------------+ | hello world | +-------------+ Pass two integers to sum (function with parameters) drop function if exists f2; delimiter // create function f2(num1 int, num2 int) returns int begin return num1 + num2; end // delimiter ; select f2(8, 2); +----------+ | f2(8, 2) | +----------+ | 10 | +----------+ 3. Custom function related syntax Show all functions: show function status\G #The output is very large Delete function: drop function [if exists] function name; 4. The difference between stored procedures and functions Stored procedures can return multiple values, while custom functions can only return one value. Stored procedures are generally executed independently, while functions are often used as part of other SQL statements. The above is what I introduced to you: Database_MySQL: Detailed explanation and integration of MySQL functions. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! You may also be interested in:
|
<<: The problem of mmx64.efi not found occurs when installing Ubuntu18 dual system on win10
>>: Vue uses three methods to refresh the page
Preface The Linux system is controlled by the sys...
Introduction to the polling algorithm Many people...
Let’s look at the effect first: This effect looks...
Comprehensive understanding of html.css overflow ...
How to check the status of Linux firewall 1. Basi...
First download the dependencies: cnpm i -S vue-uu...
Table of contents Previous 1. What is setup synta...
Nginx (engine x) is a lightweight, high-performan...
This article shares the specific code of JavaScri...
Operating system: Win7 64-bit Ultimate Edition My...
There is such a scenario: a circular container, t...
Table of contents Implementing a search engine ba...
# Adjust VMware hard disk boot priority Step 1: E...
This article shares the MySQL installation and co...
Table of contents 1. Component Organization 2. Co...