当前位置:网站首页>What functions does MySQL have? Don't look everywhere. Just look at this.
What functions does MySQL have? Don't look everywhere. Just look at this.
2022-07-28 21:05:00 【Operation and maintenance home】

Format function FPRMAT(x,n)
format(x,n) The digital x format , And keep the decimal point after... In the way of rounding n position , The result is returned as a string .
If n by 0, Then the return result function does not contain decimal part .
mysql> select format(999.12345678, 5), format(888.12345678, 0);
+-------------------------+-------------------------+
| format(999.12345678, 5) | format(888.12345678, 0) |
+-------------------------+-------------------------+
| 999.12346 | 888 |
+-------------------------+-------------------------+
1 row in set (0.00 sec)
mysql>
Numbers in different base numbers are converted to each other
conv(n, from_base, to_base) This function can convert between different base numbers . For example, will 16 Conversion of decimal digits to 2 Base number , Or 2 Conversion of decimal digits to 10 It's all right .
The return value is a number n String representation of , from from_base The base number is converted to to_base Base number . If any of the parameters is null Words , So the return value is null.
mysql> select conv('a', 16, 10) as coll, conv(123, 10, 2) as coll_1, conv(123, 10, 16) as coll_2, conv(123, 10, 8) as coll_3;
+------+---------+--------+--------+
| coll | coll_1 | coll_2 | coll_3 |
+------+---------+--------+--------+
| 10 | 1111011 | 7B | 173 |
+------+---------+--------+--------+
1 row in set (0.00 sec)
mysql>
IP Address and number conversion function
inet_auto(expr) Give a dot address representation of the network address as a string , Returns an integer representing the value of the address . The address can be 4 perhaps 8bit Address .
mysql> select inet_aton('192.168.1.1');
+--------------------------+
| inet_aton('192.168.1.1') |
+--------------------------+
| 3232235777 |
+--------------------------+
1 row in set (0.00 sec)
mysql>
conversely , We can also use inet_ntoa Function converts a numeric network address to a string network point address , To look down :
mysql> select inet_ntoa(3232235777);
+-----------------------+
| inet_ntoa(3232235777) |
+-----------------------+
| 192.168.1.1 |
+-----------------------+
1 row in set (0.00 sec)
mysql>
therefore , From above ,inet_ntoa and inet_aton They're inverse functions to each other .
Lock function and unlock function
get_lock(str, timeout) Try to use a string str Get a lock for a given name , The timeout is timeout second . If you succeed in getting the lock , Then return to 1, If the operation times out , Then return to 0; Once an error occurs , Then return to null.
release_lock(str) Untie the quilt get_lock() Acquired 、 Use string str Lock named lock . If the lock is unlocked , Then return to 1, If the thread has not created a lock , Then return to 0( The lock is not unlocked at this time ); If the named lock does not exist , Then return to null. If this lock has never been get_lock() Call to get , Or the lock has been untied in advance , Then the lock does not exist .
is_free_lock(str) Check that the name is str Whether the lock can be used , If this lock can be used , Then return to 1( No one uses this lock ); If this lock is being used , Then return to 0; If something goes wrong , Then return to null( Like incorrect parameters ).
if_used_lock(str) Check that the name is str Is your lock being used , If this is locked , Returns the connection identifier of the client using the lock , Otherwise , Just go back to null.
mysql> select get_lock('yunweijia', 15) as getlock, is_used_lock('yunweijia') as isusedlock, is_free_lock('yunweijia') as isfreelock, release_lock('yunweijia') as releaselock;
+---------+------------+------------+-------------+
| getlock | isusedlock | isfreelock | releaselock |
+---------+------------+------------+-------------+
| 1 | 8 | 0 | 1 |
+---------+------------+------------+-------------+
1 row in set (0.01 sec)
mysql>
get_lock('yunweijia', 15): The return result is 1, Description successfully got a name of ‘yunweijia’ Lock of , Duration is 15 second ;
is_used_lock('yunweijia'): The return result is the current connection id, The name is yunweijia The lock of is being used ;
is_free_lock('yunweijia'): The return is 0, The description name is yunweijia The lock of is being used ;
release_lock('yunweijia'): The return value is 1, It indicates that the unlocking is successful .
Reset the function that performs the specified operation
benchmark(count, expr) Function repetition count Number of execution expressions expr.
He can calculate with a computer mysql Speed of processing expressions . The result value is generally 0(0 It just means that the processing process is fast , Not without time ). Another function is that it can be used in mysql The execution time of the client internal report statement .
for instance :
First we use sha Function to encrypt a password , as follows :
mysql> select sha('yunweijia');
+------------------------------------------+
| sha('yunweijia') |
+------------------------------------------+
| 683501978a90d76d420b893cd7e00c8efde8e8f3 |
+------------------------------------------+
1 row in set (0.00 sec)
mysql>
You can see from above , This article sql The execution time is 0.00 sec, Then we use benchmark function , Repeat this command 50000 Time , Look at the running time ;
mysql> select benchmark(50000, sha('yunweijia'));
+------------------------------------+
| benchmark(50000, sha('yunweijia')) |
+------------------------------------+
| 0 |
+------------------------------------+
1 row in set (0.03 sec)
mysql>
As you can see from the above results , It actually runs 0.03 second .
Functions that change the character set
convert(...using...): with using Of convert() Function is used to convert data between different character sets .
mysql> select charset('yunweijia') as coll, charset(convert('yunweijia' using latin1)) as coll_1;
+---------+--------+
| coll | coll_1 |
+---------+--------+
| utf8mb3 | latin1 |
+---------+--------+
1 row in set (0.00 sec)
mysql>
See from above , The default character set is utf8mb3, adopt convert The string yunweijia The default character set of is changed to latin1.
Functions that change data types
cast(x, as type) and convert(x, type) Function converts a value of one type to a value of another type , Convertible type There are the following :
binary
char(n)
date
time
datetime
decimal
signed
unsigned
mysql> select cast(1000 as char(3)), convert('2022-07-18 09:09:00', time);
+-----------------------+--------------------------------------+
| cast(1000 as char(3)) | convert('2022-07-18 09:09:00', time) |
+-----------------------+--------------------------------------+
| 100 | 09:09:00 |
+-----------------------+--------------------------------------+
1 row in set, 1 warning (0.00 sec)
mysql>
You can see from above ,select cast(1000 as char(3)) Set integer data 1000, Convert to a string type with two display widths , The result is 100;
convert('2022-07-18 09:09:00', time) take datetime The value of type is converted to time Type values , The result is 09:09:00.
thus , In this paper, the end .
For more information, go to VX official account “ Operation and maintenance home ” , Get the latest article .
------ “ Operation and maintenance home ” ------
------ “ Operation and maintenance home ” ------
------ “ Operation and maintenance home ” ------
Linwu County operation and maintenance engineer training , Wenzhou operation and maintenance engineer , Accessible oa Implementation O & M engineer , Interview with call center operation and maintenance engineer
tencent idc shipment Interview with maintenance engineer , O & M Engineer samba, What is the industry of operation and maintenance engineers ,
Origin of operation and maintenance engineer , Operation and maintenance engineers are easy to find , Operation and maintenance Engineer access , Self study of operation and maintenance engineers is feasible
边栏推荐
- Alibaba cloud MSE supports go language traffic protection
- 全链路灰度在数据库上我们是怎么做的?
- Redis 3.0 source code analysis - data structure and object SDS list Dict
- Introduction to redis I: redis practical reading notes
- What is data center? What value does the data center bring_ Light spot technology
- 智能家居行业发展,密切关注边缘计算和小程序容器技术
- 使用缓冲的方式采集视频
- JS page black and white background switch JS special effect
- Unity foundation 6-rotation
- 蓝队入门之效率工具篇
猜你喜欢

Random talk on GIS data (VI) - projection coordinate system

The cloud native programming challenge is hot, with 510000 bonus waiting for you to challenge!

Unity - Fundamentals of 3D mathematics

智能家居行业发展,密切关注边缘计算和小程序容器技术

程序员最大的浪漫~

A 58 year old native of Anhui Province, he has become the largest IPO investor in Switzerland this year

Cause analysis of restart of EMC cx4-120 SPB controller

什么是 CI/CD? | 实现更快更好的软件交付

Explain various coordinate systems in unity in detail

Subcontracting loading of wechat applet
随机推荐
mysql还有哪些自带的函数呢?别到处找了,看这个就够了。
It is not only convenient, safe + intelligent, but also beautiful. Fluorite releases the Big Dipper face lock dl30f and Aurora face video lock y3000fv
MySQL修改端口号(修改mysql的端口号会有问题吗)
Observer mode, object pool
Dom4J的Bug
Space shooting Lesson 10: score (painting and writing)
Color finder actual combat (QT including source code)
Introduction to singleton mode
一名在读研究生的自白:我为什么会沉迷于openGauss 社区?
Hangao database best practice configuration tool Hg_ BP log collection content
C language final review questions
The 678th operation
什么是“安全感”?沃尔沃用它自己独特的理解以及行动来告诉你
mfc wpf winform(工业用mfc还是qt)
Fragment中使用ViewPager滑动浏览页面
Space shooting Lesson 13: explosion effect
The cloud native programming challenge is hot, with 510000 bonus waiting for you to challenge!
Integrating database Ecology: using eventbridge to build CDC applications
Efficientformer: lightweight vit backbone
Explain the imported 3D model in unity