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

Summary of self-taught MySql built-in function knowledge points

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

String function

Check the ascii code value of the character ascii (str). Return 0 if str is an empty string.

Select ascii ('a')

Check the character char (number) corresponding to the ascii code value.

Select char (97)

Concatenate the string concat (str1,str2...)

Select concat (12pr 34)

Contains the number of characters length (str)

Select length ('abc')

Intercept string

Left (str,len) returns the left end of the string str len character right (str,len) returns the right end of the string str len character substring (str,pos,len) returns the position of the string str pos from len character select substring ('abc123',2,3)

Remove spaces

Ltrim (str) returns the string str with the left space deleted

Rtrim (str) returns the string str with the right space deleted

Trim ([direction remstr from str) returns the string str after deleting remstr from a side. Direction words include both, leading, and trailing, indicating both sides, left and right.

Select trim ('bar'); select trim (leading'x 'FROM' xxxbarxxx'); select trim (both'x 'FROM' xxxbarxxx'); select trim (trailing'x 'FROM' xxxbarxxx'); SELECT TRIM (LEADING''FROM' my')

Returns a string space (n) consisting of n space characters

Select space (10)

Replace the string replace (str,from_str,to_str)

Select replace ('abc123','123','def')

Case conversion, the function is as follows

Lower (str) upper (str) select lower ('aBcD')

Mathematical function

Find the absolute value abs (n)

Select abs (- 32)

Find m divided by the remainder of n mod (mfocus n), same operator%

Select mod (10jue 3); select 10% 3

Floor floor (n), which represents the largest integer not greater than n

Select floor (2.3)

Ceiling ceiling (n), representing the largest integer not less than n

Select ceiling (2.3)

Round off the value round (nrecom d), where n represents the primitive number and d represents the decimal position. The default is 0.

Select round (1.6)

Find the pow of x to the power of y (xrem y)

Select pow (2pr 3)

Get pi PI ()

Select PI ()

Random number rand (), floating-point number with a value of 0-1.0

Select rand ()

There are many other trigonometric functions that can be used to query documents.

Date-time function

Get the child value, and the syntax is as follows

Year (date) returns the year of date (range 1000 to 9999) month (date) returns month value in date day (date) returns date value in date hour (time) number of hours returning time (range 0 to 23) minute (time) number of minutes returning time (range 0 to 59) second (time) number of seconds returned time (range 0 to 59) select year ('2016-12-21')

Date calculation, using the +-operator, followed by year, month, day, hour, minute, second

Select '2016-12-21'+interval 1 day

Date format date_format (date,format). Available values for the format parameter are as follows

Gets the year% Y and returns a 4-digit integer

* get the year% y and return a 2-digit integer

* get an integer of month% m with a value of 1-12

Get day% d and return an integer

* an integer with a value of 0-23 when getting% H

* an integer with a value of 1-12 when getting% h

* get an integer with a score of% I and a value of 0-59

* get seconds% s, an integer with a value of 0-59

Select date_format ('2016-12-21 million% Y% m% d')

Current date current_date ()

Select current_date ()

Current time current_time ()

Select current_time ()

Current date and time now ()

Select now ()

The above is all the relevant knowledge points of this introduction, if you have anything to add, you can contact the editor.

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