MySQL (9) -- string function (2), mysql string

Source: Internet
Author: User

MySQL (9) -- string function (2), mysql string
(8) Delete the TRIM (s1 FROM s) function of the specified string)

TRIM (s1 FROM s2) deletes all substrings s1 at both ends of string s. S1 is an optional direction. If no direction is specified, spaces are deleted.

Select trim ('xy' from 'xyxboxyokxxyxy ');

 

(9) REPEAT (s, n)

Returns a string consisting of repeated string s. The number of string s is n. If n is less than 0, an empty string is returned. If s or n is NULL, NULL is returned.

Select repeat ('mysql', 3 );

 

(10) SPACE function SPACE (n) and replacement function REPLACE (s, s1, s2)

SPACE (n) returns a string consisting of n spaces.

Select concat (', space (6 ),')');

 

 

Select replace ('xxx .mysql.com ', 'x', 'w ');

 

(11) function STRCMP (s1, s2) for comparing string sizes)

If the two strings are equal, 0 is returned. If s1 <s2,-1 is returned. Otherwise, 1 is returned.

Select strcmp ('A', 'A'), strcmp ('abc', 'acb'), strcmp ('acb', 'abc ');

 

 

(12) obtain the SUBSTRING (s, n, len) and MID (s, n. len) Functions of the SUBSTRING)

SUBSTRING (s, n, len) returns the SUBSTRING from the n position, with the length of len. MID (s, n. len) serves the same purpose as the former.

Select substring ('abcdefg', 4,3 );

 

Select mid ('abcdefg', 2, 2 );

 

(13) functions matching the starting position of a substring

The LOCATE (str1, str), POSITION (str1 IN str2), and INSTR (str, str1) functions work the same way. Returns the starting position of the substring str1 In the str string.

Select locate ('ball', 'football'), position ('ball' in 'football'), instr ('football', 'ball ');

 

(14) REVERSE string function REVERSE (s)

Select reverse ('20140901 ');

 

(15) return the string function at the specified position

ELN (N, string 1, string 2, string 3... string N) if N = 1, the return value is string 1. If N = 2, the return value is string 2...

Select elt (3, '123', 'abc', '123', 'def ');

 

(16) return FIELD (s, s1, s2…) at the specified string position ......)

Select field ('20140901', 'abc', '20160901 ');

 

(17) returns the FIND_IN_SET (s1, s2) function of the substring position)

Returns the position where string s1 appears in string s2.

Select find_in_set ('123', 'abcd, 123, efg, 100 ');

 



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.