In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
MySQL Common String Functions
From the official archives.
1.1 SUBSTR or SUBSTRING
SUBSTR(str,pos), SUBSTR(str FROM pos),SUBSTR(str,pos,len), SUBSTR(str FROM
pos FOR len)
SUBSTR() is a synonym for SUBSTRING().
SUBSTRING(str,pos), SUBSTRING(str FROM pos),SUBSTRING(str,pos,len),
SUBSTRING(str FROM pos FOR len)
The forms without a len argument return asubstring from string str starting at position pos.
The forms with a len argument return asubstring len characters long from string str, starting at
position pos. The forms that use FROM arestandard SQL syntax. It is also possible to use a negative
value for pos. In this case, the beginningof the substring is pos characters from the end of the
string, rather than the beginning. Anegative value may be used for pos in any of the forms of this
function.
For all forms of SUBSTRING(), the positionof the first character in the string from which the
substring is to be extracted is reckoned as1.
mysql> SELECTSUBSTRING('Quadratically',5);
-> 'ratically'
mysql> SELECT SUBSTRING('foobarbar' FROM4);
-> 'barbar'
mysql> SELECTSUBSTRING('Quadratically',5,6);
-> 'ratica'
mysql> SELECT SUBSTRING('Sakila', -3);
-> 'ila'
mysql> SELECT SUBSTRING('Sakila', -5,3);
-> 'aki'
mysql> SELECT SUBSTRING('Sakila' FROM -4FOR 2);
-> 'ki'
This function is multibyte safe.
If len is less than 1,the result is the empty string.
1.2 SUBSTRING_INDEX
SUBSTRING_INDEX(str,delim,count)
Returns the substring from string strbefore count occurrences of the delimiter delim. If count
is positive, everything to the left of thefinal delimiter (counting from the left) is returned. If count
is negative, everything to the right of thefinal delimiter (counting from the right) is returned.
SUBSTRING_INDEX() performs a case-sensitivematch when searching for delim.
mysql> SELECTSUBSTRING_INDEX('www.mysql.com', '. ', 2);
-> 'www.mysql'
mysql> SELECTSUBSTRING_INDEX('www.mysql.com', '. ', -2);
-> 'mysql.com'
This function is multibyte safe.
1.3 CHAR_LENGTH
CHAR_LENGTH(str) Returns the number of characters
Returns the length of the string str,measured in characters. A multibyte character counts as a
single character. This means that for astring containing five 2-byte characters, LENGTH() returns
10, whereas CHAR_LENGTH() returns 5.
1.4 LENGTH
LENGTH(str) Returns the number of bytes
Returns the length of the string str,measured in bytes. A multibyte character counts as multiple
bytes. This means that for a stringcontaining five 2-byte characters, LENGTH() returns 10, whereas
CHAR_LENGTH() returns 5.
mysql> SELECT LENGTH('text');
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.