Several common uses of MySQL string processing functions

Source: Internet
Author: User
Tags lowercase

1. String Case Conversion:

(1). Replace all lowercase letters in the user_name field of the Tbl_student table with uppercase:

Update tbl_student set User_name=upper (user_name);

(2). Replace all uppercase letters in the User_name field of the Tbl_student table with lowercase:

Update tbl_student set User_name=lower (user_name);

2. Clear the string leading or trailing spaces, or specify the characters:

(1). Clear the User_name field of the Tbl_student table the leading and trailing spaces

Update tbl_student Set User_name=trim ("from user_name);

(2). Clear the string header with the specified character a:

Update Tbl_student Set User_name=trim (Leading ' A ' from user_name);

(3). Clear string trailing specified character b

Update tbl_student set User_name=trim (TRAILING ' B ' from user_name);

3. Replace the string:

(1). The number 1 in the replacement string is the letter I

Update tbl_student Set User_name=replace (user_name, ' 1 ', ' I ');

4. Using the Regular (REGEXP):

(1). If the ending two is a letter, remove

Update tbl_student Stu Stu.user_name=substring (Stu.user_name,length (Stu.user_name)-2) where Stu.user_name REGEXP ' [ A-za-z]{2,}$ ';

Several common uses of MySQL string processing functions

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.