Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of mysql function

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article will explain in detail the example analysis of the mysql function for you. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

one。 Built-in function

1. Mathematical function

Rand () round (num) ceil (num) floor (num) is randomly rounded up and down

two。 String function

Length () byte length

Char_length () character length

Ucase () capital case

Lcase () lowercase

Concat (character, … , character n) connection string

Replace (string, old character, new character) string replacement

Intercept string

Left (string, intercept length)

Right (string, intercept length)

Substring (string, start position, intercept length) # contains the start position

Mysql > select left ('123456 sec 4); +-+ | left (' 123456 sec 4) | +-+ | 1234 | +-+ 1 row in set (0.00 sec) mysql > select right ('123456 sec 4) +-+ | right ('123456 sec 4) | +-+ | 3456 | +-+ 1 row in set (0.00 sec) mysql > select substring (' 123456 sec 2) +-+ | substring ('123456 row in set 2 sec 4) | +-+ | 2345 | +-+ 1 sec)

3. Date function

Now () unix_timestamp () from_unixtime () current timestamp formatted timestamp mysql > select now () +-+ | now () | +-+ | 0-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) | +-- + | 0-03-16 14:55:56 | +-- + 1 row in set (2019 sec) year () month () day ( ) hour () minute () second () year, month, day, hour, mysql > select-> year (now ()) as' year' -> month (now ()) as' month',-> day (now ()) as' day',-> hour (now ()) as' hour',-> minute (now ()) as' minute',-> second (now ()) as' second' +-+ | year | month | Day | hours | minutes | seconds | +-+-+ | 2019 | 3 | 16 | 14 | 59 | 12 | +-+ -- +

4. Encryption function

Md5 (data)

Password (data)

5. Conditional judgment function

1)。 Syntax: if (data, value 1, value 2) # determines whether the specified data is true: true-value 1, false-value 2

Mysql > select if (null,1,2); +-+ | if (null,1,2) | +-+ | 2 | +-+ 1 row in set (0.00 sec) mysql > select if +-+ | if (1 sec 0) | +-+ | 0 | +-+ 1 sec

2)。 Syntax: IFNULL (data, value 2) # determines whether the specified data is a null:null- value of 2, not null- itself

Mysql > select ifnull (0123); +-+ | ifnull (0123) | +-+ | 0 | +-+ 1 row in set (0.00 sec) mysql > select ifnull ('aaqule123) +-+ | ifnull ('axiomagore123) | +-+ | a | +-+ 1 row in set (0.00 sec)

two。 Custom function

Syntax:

# modify Terminator delimiter / / create function function name (parameter name type,..., parameter name n type n) returns returns data type begin#SQL statement return return value; end / / delimiter; # call select function name ()

Output "hello world" (function without arguments)

# to determine whether the function exists, delete drop function if exists f1bot delimiter / / create function F1 () returns varchar (30) begin return 'hello world';end / / delimiter; select F1 (); +-+ | F1 () | +-+ | hello world | +-+

Pass the sum of two integers (a function with parameters)

Drop function if exists f2dexdelimiter / create function f2 (num1 int, num2 int) returns intbegin return num1 + num2;end / / delimiter; select f2 (8,2); +-+ | f2 (8,2) | +-+ | 10 | +-+

three。 Custom function related syntax

Show all the functions: show function status\ G # output a lot of content

Delete function: drop function [if exists] function name

four。 The difference between stored procedures and functions

Stored procedures can return multiple values, while custom functions can return only one value

Stored procedures are generally executed independently, while functions are often used as part of other SQL statements

This is the end of this article on "example Analysis of mysql function". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report