In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
First, we need to understand the string interception function:
Left (), right (), substring (), substring_index (). And mid (), substr (). Among them, mid (), substr () is equivalent to the substring () function, substring () is very powerful and flexible.
Specific examples are as follows:
1. String interception: left (str, length) mysql > select left ('sqlstudy.com', 3) +-+ | left ('sqlstudy.com', 3) | +-+ | sql | +-+ 2. String interception: right (str, length) mysql > select right ('sqlstudy.com', 3) +-- + | right ('sqlstudy.com', 3) | +-- + | com | +-+ 3. String interception: substring (str, pos); substring (str, pos, len) 3.1 starts at the fourth character position of the string and ends. Mysql > select substring ('sqlstudy.com', 4) +-- + | substring ('sqlstudy.com' 4) | +-+ | study.com | +-- + 3.2 start from the fourth character position of the string Take only 2 characters. Mysql > select substring ('sqlstudy.com', 4,2) +-- + | substring ('sqlstudy.com', 4 2) | +-- + | st | +-- + 3.3 start from the fourth character position (reciprocal) of the string Until the end. Mysql > select substring ('sqlstudy.com',-4) +-- + | substring ('sqlstudy.com' -4) | +-- + | .com | +-- + 3.4 start from the fourth character position (reciprocal) of the string Take only 2 characters. Mysql > select substring ('sqlstudy.com',-4,2) +-- + | substring ('sqlstudy.com',-4) 2) | +-- + | .c | +-- + We noticed that in the function substring (str,pos, len) Pos can be negative, but len cannot be negative. 4. String interception: substring_index (str,delim,count) 4.1 intercepts the second'.' All the previous characters. Mysql > select substring_index ('www.sqlstudy.com.cn','. 2) +-- + | substring_index ('www.sqlstudy.com.cn','.' 2) | +-+ | www.sqlstudy | + -+ 4.2 intercept all characters after the second'.'(countdown). Mysql > select substring_index ('www.sqlstudy.com.cn','.'- 2) +-- + | substring_index ('www.sqlstudy.com.cn','.' -2) | +-+ | com.cn | +-- -+ 4.3If the value specified by the delim parameter is not found in the string The entire string mysql > select substring_index ('www.sqlstudy.com.cn',' .coc', 1) is returned +-- + | substring_index ('www.sqlstudy.com.cn',' .coc' 1) | +-- + | www.sqlstudy.com.cn | +-- -+ 4.4 intercept the intermediate value of a field data in a table if the field data is 1pc2 3 mysql > select substring_index (substring_index (the field,',', 2),',',-1) from table name +-- + | substring_index (substring_index (this field,',', 2) ,',' -1) | +-+ | 2 | +- -- +
These are the details of mysql string interception, please pay attention to other related articles!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.