In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article is mainly about the basic usage of the MySQL MID () function. If you are interested, let's take a look at this article. I believe it will be of some reference value to you after reading the basic usage of the MySQL MID () function.
In MySQL, the MID () function returns a substring starting at the specified location.
MID () and SUBSTR () are both synonyms for SUBSTRING ().
The basic syntax is as follows:
MID (str,pos,len)
Here, str is the string, pos is the position of the starting substring, and len is an optional parameter that determines the number of characters returned from the starting position.
There are several different ways to use this function, so the complete syntax looks like this:
MID (str,pos) MID (str FROM pos) MID (str,pos,len) MID (str FROM pos FOR len)
Example 1-basic usage
Here is an example of the MID (str,pos) syntax:
SELECT MID ('I drink coffee', 3) Result
Results:
+-| Result | +-+ | drink coffee | +-+
In this case, I take a substring from the string, starting at position 3.
Example 2-using the FROM clause
This time the MID (str FROM pos) syntax is used:
SELECT MID ('I drink coffee' FROM 3) Result
Results:
+-| Result | +-+ | drink coffee | +-+
The result is the same.
In this case, FROM is the standard SQL. Note that this syntax does not use commas.
Example 3-specify length
In this example, I used the MID (str,pos,len) syntax:
SELECT MID ('I drink coffee', 3,5) Result
Results:
+-| Result | +-+ | drink | +-+
Here I specify that the length of the returned substring is 5 characters.
Example 4-specify the length (using the FOR clause)
In this example, I used the MID (str FROM pos FOR len) syntax:
SELECT MID ('I drink coffee' FROM 3 FOR 5) Result
Results:
+-| Result | +-+ | drink | +-+
So this time we use standard SQL to achieve the same result.
Does the above details about the basic usage of the MySQL MID () function help you? If you want to know more about it, you can continue to follow our industry information section.
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.