Home >Database >Mysql Tutorial >Which MySQL function returns a specified number of strings as output?

Which MySQL function returns a specified number of strings as output?

WBOY
WBOYforward
2023-08-25 11:01:041267browse

哪个 MySQL 函数返回指定数量的字符串作为输出?

MySQL returns the specified number of characters in a string with the help of the LEFT() and RIGHT() functions.

MySQL LEFT() function will return the specified number of characters from the left side of the string.

Syntax

LEFT(str, length)

Here str is a string of multiple characters to be returned, and the length is an integer value specifying the number of characters to be returned.

Example

mysql> Select LEFT('My Name is Ram', 7);
+---------------------------+
| LEFT('My Name is Ram', 7) |
+---------------------------+
| My Name                   |
+---------------------------+
1 row in set (0.00 sec)

The MySQL RIGHT() function will return the specified number of characters from the right side of a string.

Syntax

RIGHT(str, length)

Here str is a string of multiple characters to be returned, and the length is an integer value specifying the number of characters to be returned.

Example

mysql> Select RIGHT('My name is Ram',6);
+---------------------------+
| RIGHT('My name is Ram',6) |
+---------------------------+
| is Ram                    |
+---------------------------+
1 row in set (0.00 sec)

The above is the detailed content of Which MySQL function returns a specified number of strings as output?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete