Several useful MySQL functions

Tram Ho

Querying out data and then processing it in a programming language is cool, but did you know that MySQL has provided some of these useful functions for us as well?


Actually, it is just the same

we will write instead

Hmm actually I think this MySql style is longer than that but it’s nice to know one more new one.


Usage is the same as CHARACTER_LENGTH. But the use is completely different

number: the number we need to format
decimal_places: hearing the name, we type is the position of the decimal number, but you just understand that the number of decimal places is simply added. For example


Remove terminal whitespace.
This is quite good because if you query out a Post object and have a content field that needs to trim the title in many places, instead of everywhere, post.content.strip prone to miss, you can trim right at the example query. as


Its use is similar to ruby’s gsub – Replace all a character or string with another character or string.

For example:


Returns the maximum and minimum value. For example:


Convert format of date data type Example:


This I think everyone should know because of it, it supports me a lot in cases of selecting according to conditions.
For example:

firsttwelfthThe quantity is under 30
240The quantity is greater than 30
3tenThe quantity is under 30


Converts values ​​to a specific data type.
For example:


Returns the first value that is not Nulled


Too familiar but its syntax is like this


Here are some functions that I myself think will be useful (in a bunch of available MySQL functions). Hope it helps everyone too (bow)

Share the news now

Source : Viblo