What is the usage of the MySQL substring function?

The substring function in MySQL is used to extract a portion of a string.

Syntax:
SUBSTRING(str, start, length)

Parameters:

  1. String: the string to be extracted.
  2. Start: Specify the starting position for extraction, with counting starting from 1.
  3. A parameter called “length” is optional and specifies the number of characters to extract. If “length” is not specified, all characters from the “start” position to the end of the string are returned.

For example, if we have a string “Hello World”, we can use the substring function to extract a portion of it.

SELECT SUBSTRING(‘Hello World’, 7) AS ‘Output’; — Output: World

Return the substring ‘World’ starting from the 7th position in the string ‘Hello World’.

Output: Hello

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds