Mysql for databases (6) -- mysql common functions/user-defined functions, mysql Functions

Source: Internet
Author: User
Tags md5 encryption mysql functions

Mysql for databases (6) -- mysql common functions/user-defined functions, mysql Functions
Common functionsOperation Functions










I believe you can understand it, so I will not explain it too much.


Then there is another, missed between and:


Indicates whether 10 is between 0 and 20. If 1 is returned, otherwise 0 is returned.


Date Functions







Note that the first parameter is the start date, interval is fixed, 2 is the number of days to be added, and the following day is the unit, or week, year. 







Information Functions







Aggregate functions









Because the tables in my test database do not have good data, the operation result is very strange. Sorry, you know how to use it.


Encryption Functions




I personally think these two encryption functions are not very secure.

Although the md5 encryption operation is irreversible (it is not allowed to use the encrypted data for reverse translation), the encrypted data is regular, do not believe that you can operate on your own computer to see if the encrypted "testing" is the same as mine, so long as you can integrate all the data encrypted by md5 into a database, then you can decrypt the code one by one. And the password method can also be in this situation,


However, in general operations, it is enough to use these two encryption functions.


Custom functions:

1) Necessary Conditions for user-defined functions:

  • There can be zero or multiple parameters
  • Only one value can be returned.


There can be no inevitable relationship between parameters and return values. All functions have return values, but the parameters are not necessarily.

The function can return any type of data, or accept any type of data as a parameter.


2) User-Defined Function body:


3) Example:

A: No Parameters

  • Returns specifies the data type returned by the function.
  • Return is used to return specific values/value variables.
  • The function name must be enclosed in parentheses. Otherwise, an error is returned.


B: With parameters:


C: Create Compound Functions

Current table information:




The error is reported because mysql ends with a semicolon by default, and data is not inserted into the table.


You can change the default end character of mysql from semicolon //


Create and view data again:



D: delete a UDF. 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.