MySQL string manipulation

Source: Internet
Author: User
Tags strcmp

--The length of the string

SELECT Length (' abc '), Length (' My home ');

SELECT char_length (' abc '), Char_length (' my Home ');

--Merging strings

SELECT CONCAT (' A ', ' B ', ' C '), Concat_ws (', ', ' A ', ' B ', ' C '), CONCAT (null, ' a '), Concat_ws ('-', ' 010 ', NULL, ' 1111 ', ' 2222 ')

--Replacement string

SELECT INSERT (' ABCDEFG ', 2,10, ' 1111111111 '), REPLACE (' ABCDEFG ', ' abc ', ' 111 ')

--String case

SELECT LOWER (' abc '), LCASE (' abc '), UPPER (' abc '), UCASE (' abc ')

--Get string

SELECT left (' ABCDEFG ', 3), right (' ABCDEFG ', 3)

--Padding string

SELECT lpad (' abc ', 5, ' * '), Rpad (' abc ', 5, ' * '), Rpad (' ABCEFG ', 5, ' * ')

--Remove spaces

SELECT Trim (' * ' from ' **abc** '), trim (' abc '), LTRIM (' abc '), RTRIM (' abc ')

--Duplicate string generation

SELECT REPEAT (' abc ', 3)

--Space function

SELECT Concat_ws (Space (3), ' B ', Space (3), ' a ')


--Compare string size

SELECT STRCMP (' abc ', ' Abd '), STRCMP (' abc ', ' abc '), STRCMP (' Abe ', ' Abd ')

--Get string

SELECT SUBSTRING (' 0,1,2,3 ', 5,2), SUBSTRING (' 0,1,2,3 ', 5), Mid (' 0,1,2,3 ', 5,2), Mid (' 0,1,2,3 ', 5)

--Reverse string

SELECT REVERSE (' ABCDEFG ')

--Match string start position

SELECT LOCATE (' ab ', ' DGDSABDFDSA '), POSITION (' ab ' in ' Dgdsabdfdsa '), INSTR (' Dgdsabdfdsa ', ' ab '), Find_in_set (' Ab ', ' Dgdsabdfdsa,ab|,ab ')

--Returns the string at the specified position

SELECT ELT (2, ' A ', ' B ', ' C '), FIELD (' B ', ' A ', ' B ', ' C '), ELT (2, ' a,b,c ')

--Binary

SELECT Make_set (5, ' A ', ' B ', ' C ');

MySQL string manipulation

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.