MySQL - String Functions

Last Updated : 14 Aug, 2026

MySQL provides String Functions to perform operations on text values, such as combining, modifying, searching and extracting strings.

  • Used to manipulate and process text data.
  • Help combine, extract and modify string values.
  • Can be used with SELECT queries.
  • Useful for data cleaning and formatting.

Common MySQL String Functions

FunctionDescription
CONCAT()Combines two or more strings.
CONCAT_WS()Combines strings using a separator.
LENGTH()Returns the length of a string in bytes.
CHAR_LENGTH()Returns the number of characters in a string.
UPPER()Converts a string to uppercase.
LOWER()Converts a string to lowercase.
TRIM()Removes leading and trailing spaces.
LTRIM()Removes leading spaces.
RTRIM()Removes trailing spaces.
SUBSTRING()Extracts a part of a string.
LEFT()Returns characters from the beginning of a string.
RIGHT()Returns characters from the end of a string.
REPLACE()Replaces part of a string with another value.
REVERSE()Reverses a string.
INSTR()Finds the position of a substring.

CONCAT()

The CONCAT() function combines two or more strings into a single string.

Syntax:

CONCAT(string1, string2, ...);

Example:

SELECT CONCAT('Hello', ' ', 'World') AS result;

Output:

Screenshot-2026-08-14-100245

CONCAT_WS()

The CONCAT_WS() function combines strings using a specified separator.

Syntax:

CONCAT_WS(separator, string1, string2, ...);

Example:

SELECT CONCAT_WS('-', '2026', '08', '13') AS result;

Output:

Screenshot-2026-08-14-100328

LENGTH()

The LENGTH() function returns the length of a string in bytes.

Syntax:

LENGTH(string);

Example:

SELECT LENGTH('MySQL') AS length;

Output:

Screenshot-2026-08-14-100350

CHAR_LENGTH()

The CHAR_LENGTH() function returns the number of characters in a string.

Syntax:

CHAR_LENGTH(string);

Example:

SELECT CHAR_LENGTH('MySQL') AS characters;

Output:

Screenshot-2026-08-14-100350

UPPER()

The UPPER() function converts all characters in a string to uppercase.

Syntax:

UPPER(string);

Example:

SELECT UPPER('mysql') AS result;

Output:

Screenshot-2026-08-14-100544

LOWER()

The LOWER() function converts all characters in a string to lowercase.

Syntax:

LOWER(string);

Example:

SELECT LOWER('MYSQL') AS result;

Output:

Screenshot-2026-08-14-100544

TRIM()

The TRIM() function removes leading and trailing spaces from a string.

Syntax:

TRIM(string);

Example:

SELECT TRIM('  MySQL  ') AS result;

Output:

Screenshot-2026-08-14-113655

LTRIM()

The LTRIM() function removes spaces from the beginning of a string.

Syntax:

LTRIM(string);

Example:

SELECT LTRIM('  MySQL') AS result;

Output:

Screenshot-2026-08-14-113710

RTRIM()

The RTRIM() function removes spaces from the end of a string.

Syntax:

RTRIM(string);

Example:

SELECT RTRIM('MySQL  ') AS result;

Output:

Screenshot-2026-08-14-113732

SUBSTRING()

The SUBSTRING() function extracts a portion of a string.

Syntax:

SUBSTRING(string, start, length);

Example:

SELECT SUBSTRING('MySQL Database', 1, 5) AS result;

Output:


Screenshot-2026-08-14-113732

LEFT()

The LEFT() function returns a specified number of characters from the beginning of a string.

Syntax:

LEFT(string, number);

Example:

SELECT LEFT('MySQL Database', 5) AS result;

Output:

Screenshot-2026-08-14-113732

The RIGHT() function returns a specified number of characters from the end of a string.

Syntax:

RIGHT(string, number);

Example:

SELECT RIGHT('MySQL Database', 8) AS result;

Output:

Screenshot-2026-08-14-113837

REPLACE()

The REPLACE() function replaces a specified part of a string with another value.

Syntax:

REPLACE(string, old_string, new_string);

Example:

SELECT REPLACE('MySQL Database', 'MySQL', 'SQL') AS result;

Output:

Screenshot-2026-08-14-114350

REVERSE()

The REVERSE() function reverses a string.

Syntax:

REVERSE(string);

Example:

SELECT REVERSE('MySQL') AS result;

Output:

Screenshot-2026-08-14-114410

INSTR()

The INSTR() function returns the position of the first occurrence of a substring in a string.

Syntax:

INSTR(string, substring);

Example:

SELECT INSTR('MySQL Database', 'Database') AS position;

Output:

Screenshot-2026-08-14-114430
Comment

Explore