Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Database \ MySQL common functions summary     - Objective-C basic program structure (Programming)

- Linux basic introductory tutorial ---- Software Installation under Linux (Linux)

- Source install Python3.4 on CentOS (Linux)

- Using IE can also be easily remotely control the computer (Linux)

- A simple shell script for monitoring in Linux (Linux)

- Multi-core CPU, multi-threading and parallel computation (Linux)

- Linux Operating System Security Management describes the top ten tricks (Linux)

- Spark parquet merge metadata problem (Server)

- Analytical Ceph: handle network layer (Server)

- Nginx is used to build the cache module srcache_nginx (Server)

- OpenJDK 7 compiled under Ubuntu 14.04.3 64-bit (Linux)

- Linux Creating a new user error Creating mailbox file: File exists (Linux)

- CentOS 7 Configure logging (VirtualBox) (Linux)

- Java reflection summary (Programming)

- Linux common commands MEMO (Linux)

- httpd-2.4 feature (Server)

- Kitematic how seamless and DockerFILE (Server)

- php How to prevent being injected (Linux)

- Bash Automated Customization Linux belongs to its own CentOS system (Linux)

- ORA-4031 error Solution (Database)

 
         
  MySQL common functions summary
     
  Add Date : 2018-11-21      
         
         
         
  First, Mathematical Functions

1. The absolute value function abs (value)

 mysql> select abs (-120);
+ ----------- +
| Abs (-120) |
+ ----------- +
| 120 |
+ ----------- +
1 row in set (0.00 sec)

2. Floor function floor (value), get less than the maximum integer value

mysql> select floor (23.8);
+ ------------- +
| Floor (23.8) |
+ ------------- +
| 23 |
+ ------------- +
1 row in set (0.00 sec)

3. The ceiling function ceiling (value), the smallest integer value greater than acquisition

mysql> select ceiling (23.8);
+ --------------- +
| Ceiling (23.8) |
+ --------------- +
| 24 |
+ --------------- +
1 row in set (0.00 sec)

4. rounding function round (value, position), rounded to decimal places

mysql> select round (23.27); - default is 0
+ -------------- +
| Round (23.27) |
+ -------------- +
| 23 |
+ -------------- +
1 row in set (0.00 sec)

mysql> select round (23.27,1);
+ ---------------- +
| Round (23.27,1) |
+ ---------------- +
| 23.3 |
+ ---------------- +
1 row in set (0.00 sec)

5. The random number function rand (), get a random number between 0-1

mysql> select rand ();
+ --------------------- +
| Rand () |
+ --------------------- +
| 0.12718137365503365 |
+ --------------------- +
1 row in set (0.00 sec)

Second, String Functions

1. Connect function concat (str1, str2)

mysql> select concat ( 'hello', 'world');
+ ------------------------- +
| Concat ( 'hello', 'world') |
+ ------------------------- +
| Helloworld |
+ ------------------------- +
1 row in set (0.00 sec)

2. delimited copula concat_ws (separator, str1, str2)

mysql> select concat_ws ( '#', 'hello', 'world');
+ -------------------------------- +
| Concat_ws ( '#', 'hello', 'world') |
+ -------------------------------- +
| Hello # world |
+ -------------------------------- +
1 row in set (0.00 sec)

3. Number of Bytes string length (str)

mysql> select length ( 'helloworld I');
+ ------------------------ +
| Length ( 'helloworld I') |
+ ------------------------ +
| 12 |
+ ------------------------ +
1 row in set (0.00 sec)

4. The number of characters in a string char_length (str)

mysql> select char_length ( 'helloworld I');
+ ----------------------------- +
| Char_length ( 'helloworld I') |
+ ----------------------------- +
| 12 |
+ ----------------------------- +
1 row in set (0.00 sec)

5. String Functions judgment

. A IF (exp1, exp2, exp3): If exp1 true return exp2; exp1 if false, return exp3

mysql> select if (2> 1, 'hello', 'world');
+ ------------------------- +
| If (2> 1, 'hello', 'world') |
+ ------------------------- +
| Hello |
+ ------------------------- +
1 row in set (0.00 sec)

mysql> select if (null = 1, 'hello', 'world');
+ ---------------------------- +
| If (null = 1, 'hello', 'world') |
+ ---------------------------- +
| World |
+ ---------------------------- +
1 row in set (0.08 sec)

. B IFNULL (exp1, exp2): If exp1 IS NOT NULL, returns exp1, otherwise exp2

 mysql> select IFNULL ( 'hello', 'world');
+ ------------------------- +
| IFNULL ( 'hello', 'world') |
+ ------------------------- +
| Hello |
+ ------------------------- +
1 row in set (0.00 sec)

mysql> select IFNULL (null, 'world');
+ ---------------------- +
| IFNULL (null, 'world') |
+ ---------------------- +
| World |
+ ---------------------- +
1 row in set (0.06 sec)

. C NULLIF (exp1, exp2): If exp1 = exp2, returns NULL, otherwise exp1

mysql> select NULLIF ( 'hello', 'hello');
+ ------------------------- +
| NULLIF ( 'hello', 'hello') |
+ ------------------------- +
| NULL |
+ ------------------------- +
1 row in set (0.00 sec)

mysql> select NULLIF ( 'hello', 'hello11');
+ --------------------------- +
| NULLIF ( 'hello', 'hello11') |
+ --------------------------- +
| Hello |
+ --------------------------- +
1 row in set (0.00 sec)

6. string conversion functions

. A LTRIM (exp1): removed beginning exp1 string (LEFT) space

mysql> select LTRIM ( 'HELLO');
+ ------------------ +
| LTRIM ( 'HELLO') |
+ ------------------ +
| HELLO |
+ ------------------ +
1 row in set (0.00 sec)

b.RTRIM (exp1): remove exp1 the end of the string (RIGHT) space

mysql> select LTRIM ( 'HELLO');
+ -------------------------- +
| LTRIM ( 'HELLO') |
+ -------------------------- +
| HELLO |
+ -------------------------- +
1 row in set (0.00 sec)

c.TRIM (exp1): remove exp1 the leading and trailing spaces

mysql> select TRIM ( 'HELLO');
+ ------------------------- +
| TRIM ( 'HELLO') |
+ ------------------------- +
| HELLO |
+ ------------------------- +
1 row in set (0.00 sec)

7. string search function

a.SUBSTRING_INDEX (exp1, delim, count), which exp1 a string, delim as a split symbol, count represents the first of several style symbol

mysql> select substring_index ( '1121.qq..com',, 1 '.');
+ --------------------------------------- +
| Substring_index ( '1121.qq..com',, 1 '.') |
+ --------------------------------------- +
| 1121 |
+ --------------------------------------- +
1 row in set (0.00 sec)

. B SUBSTRING (exp1, pos, len): exp1 a string, pos for the location, len is the length

mysql> select substring ( '1121.qq.com', 1,9);
+ ------------------------------ +
| Substring ( '1121.qq.com', 1,9) |
+ ------------------------------ +
| 1121.qq.c |
+ ---------------------------- +
1 row in set (0.00 sec)

8. Date Manipulation Functions
Date Format Conversion Functions
Way to convert a string to a date format DATE_FORMAT () or STR_TO_DATE (), the following two functions
DATE_FORMAT (expr1, format)
STR_TO_DATE (expr1, format) a
Common date format YYYY-MM-DD HH: MM: SS format corresponding to% Y-% m-% d% H:% i:% S
Date arithmetic functions
CURDATE (): Returns the day's date in the format: YYYY-MM-DD
NOW (): Returns the current date and time in the format: YYYY-MM-DD HH: MM: SS
DATE_ADD (date, INTERVAL expr unit): expr expression, unit to unit,

E.g:
DATE_ADD ( '2013-08-20', INTERVAL -1 DAY), returns: 2013-08-19

9. The date arithmetic functions
MONTH (date): Returns the number of months of the date such MONTY ( '2013-08-20'), returns: 8
DAY (date): Returns the number of days of date of such DAY ( '2013-08-20'), return: 20
YEAR (date): Returns the number of years of the date, such as YEAR ( '2013-08-20'), returns: 2013
TO_DAYS (date): date corresponding to the number of days, for example TO_DAYS ( '2008-10-07'), return: 733 687
WEEK (date): Returns the date corresponding to the day of the week, such as: WEEK ( '2013-08-20'), returns: 2
DATEDIFF (date1, date2): Returns the number of days difference between date1-date2, for example:
DATEDIFF ( '2013-08-20', '2013-08-18 13:30:14'), returns: 2

10. Type Conversion Functions
CAST (expr AS type): expr converted to a certain type
CONVERT (expr, type): expr converted to a certain type
CONVERT (expr USING transcoding_name): expr character set is converted to a character set
     
         
         
         
  More:      
 
- Detailed PHP code optimization [section] (explain reasons) (Programming)
- Java implementation chain store binary tree (Programming)
- linux server security (Linux)
- Oracle SQL statement to retrieve data paging table (Database)
- Linux System Getting Started Tutorial: mounted directly in Linux LVM partition (Linux)
- Linux, ls command to achieve (Linux)
- Create and modify Oracle temporary table space (Database)
- Linux port mapping system (routing and forwarding) (Server)
- Shell script on the variables with double quotation marks grep small problem (Programming)
- OpenSSL to generate public and private key (Linux)
- CentOS install Java 1.8 (Linux)
- Linux log management make the system more secure (Linux)
- Job achieve automation in Ubuntu 14.04 - Using Cron (Linux)
- MySQL high availability cluster fragmentation of deployment uses Fabric (Database)
- OpenSSH version smooth upgrade method (Linux)
- To explore the caching mechanism for Android ListView (Programming)
- Installation JDK 1.8 under CentOS7 (Linux)
- Setting Hibernate connection MySQL database connection pool coding (Database)
- Installation and Configuration JDK8 In CentOS 7 (Linux)
- GDB remote connections RX Probe online debug program (Programming)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.