MySQL Self-study chapter (ix)--string function (ii)

Source: Internet
Author: User
Tags strcmp

(8) to delete the function of the specified stringTRIM (S1 from S)

TRIM (S1 from S2) deletes all substrings in the string s s1. S1 is optional, and when unspecified, removes spaces.

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

(9) function for repeating string generationREPEAT (s,n)

Returns a string consisting of a repeating string s , and the number of s is n. If n<0, returns an empty string. returns null if s or n is null

Select repeat (' MySQL ', 3);

(Ten) space functionSPACE (n)and replace functionsREPLACE (S,S1,S2)

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

Select Concat (' (', Space (6), ') ');

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

( Onea function that compares the size of a stringSTRCMP (S1,S2)

Returns 0if two strings are equal,or 1if s1<s2returns 1

Select strcmp (' AA ', ' AA '), strcmp (' abc ', ' ACB '), strcmp (' ACB ', ' abc ');

(12) Get the SUBSTRING function substring (s,n,len)and theMID (S,n.len)

SUBSTRING (S,n,len) returns a substring of length len that was searched from n position . MID (s,n.len) acts the same as the former.

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

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

(13) function to match the starting position of a substring

LOCATE (STR1,STR),POSITION (str1 in str2) and INSTR (STR,STR1) 3 functions are the same. Returns the starting position of the substring str1 in the string str

Select locate (' Ball ', ' football '), position (' ball ' in ' Football '), InStr (' Football ', ' Ball ');

(14) Inverse string function reverse (s)

Select reverse (' 12345 ');

(15) Returns a string function at the specified position

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

Select ELT (3, ' 123 ', ' abc ', ' 456 ', ' def ');

(16) Returns the location of the specified string in the return field (S,S1,S2...)

Select field (' 123 ', ' abc ', ' 123 ');

(17) function Find_in_set (S1,S2) to return substring position

Returns the position where the string S1 appears in the string s2 .

Select Find_in_set (' 123 ', ' abcd,1234,efg,123 ');



MySQL Self-study chapter (ix)--string function (ii)

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.