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

Common functions of MySQL

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

Share

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

1. Mathematical function

ABS (X) absolute value

CEIL (X) rounding up

FLOOR (X) rounding down

Random numbers of RAND (X) 0-1

ROUND (X) the integer closest to x

ROUND (XQuery Y) retains the decimal place y after x and is rounded when truncated

POW (Xmai Y) to the y power

SQRT (XQuery Y) opens the y-th root,

two。 Character function

CHAR_LENGTH (X) takes the character length "I am L" = > 3

LENGTH (X) takes the byte length "I am L" = > 6

CONCAT (A1 and A2) concatenates two characters

UPPER (X) LOWER (X) upper case, lowercase

LEFT (XMagne N) RIGHT (XMagne N) takes n characters from the left / right

REPLACE (SMagazine S1 and S2) replace S1 in the string s with S2

MID (SMagneN LN) intercepts substrings of ln length starting with n in the string s

REVERSE (X) string s is reversed

3. Date function

Common function

CURDATE () returns the current date without time

CURTIME () returns the current time without a date

NOW () returns the current time + date

Conversion function

Returns the month in a given date

What month is the day in MONTH (D) d from January to December?

The name of the month of the day in MONTHNAME (D) d

Returns the week in a given date

What day is this day in DAYNAME (D) d?

What day is it in DAYOFWEEK (D) d 1 Sunday 2 Monday

What day is it in WEEKDAY (D) d? Monday 1 Tuesday.

This day in WEEK (D) d is the week of the year.

Returns the details of a given date

The year in DAYORYEAR (D) d

Which month is it in DAYOFMONT (D) d

The quarter in QUARTER (D) d

Hourly value in HOUR (D) d

Minute value in MINUTE (D) d

Second value in SECOND (D) d

Calculation of time

TIME_TO_SEC (T) converts a given time t into seconds

SEC_TO_TIME (T) converts time in seconds into time-minute-second format.

DATEDIFF (D1 and D2) calculates the number of days between D1 and D2

ADDDATE (interval N) calculate the start date plus a time period after the date n defaults to days or hours interval 5 date

SUBDATE date minus n-day date

The date value of a SUBDATE date minus a time period can be INTERVAL 10 minute

DATA_FORMAT (DJE F) displays the date'% Y-%m-%d% r'as required by the expression f

TIME_FORMAT (DMague F) displays the time'% r'as required by the expression f

4. Conditional function

IF (EXPR,V1,V2) if the expression holds that 3 > 2 satisfies the condition, then return the result v1 otherwise v2

IF (1 > 0, correct, wrong) returns v2 if the expression is null otherwise v1

IFNULL (V1 Magi V2) returns v2 if the value of v1 is empty, otherwise returns v2

CASE

CASE

WHEN e1

THEN v1

WHEN e2

THEN e2

...

ELSE vn

END

5. Encryption function

PASSWORD (STR) this function encrypts the string str. In general, PASSWORD (str) is used to encrypt the user's password.

The MD5 MD5 (str) function can hash the string str and can be used for some ordinary data encryption that does not need to be decrypted.

The ENCODE (STR,PSWD_STR) and DECODE (CRYPT,PSWD_STR) ENCODE functions can use the encryption password pswd_str to encrypt the string str. The encryption result is a binary number and needs to be saved using a field of type BLOB. This function is paired with DECODE and requires the same password to decrypt.

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