4. MYSQL common functions (string functions)

 

Table of contents

1. concat function:

2. insert (str, x, y, instr) function:

3. The lower(str) and upper(str) functions:

 4. Left(str,x) and right(str,x) functions:

5. lpad(str,n,pad) and rpad(str,n,pad) functions:

6. ltrim(str) and rtrim(str) functions:

 7. The repeat(str,x) function:

 8. replace(str,a,b) function:

9. trim (str) function:

 10. strcmp(s1, s2) function:

 11. substring (str, x, y) function:


1. concat function:

Concatenate the incoming parameters into a string

select concat('aaa', 'bbb', 'ccc') ,concat('aaa',null);

2. insert (str, x, y, instr) function:

Replace the string str starting with x string, y string length with instr

select INSERT('beijing2008you',12,3, 'me') ;

3. The lower(str) and upper(str) functions:

Replace all strings with uppercase or lowercase

select LOWER('BEIJING2008'), UPPER('beijing2008');

 4. Left(str,x) and right(str,x) functions:

x characters from the far left (right) side of the string

 SELECT LEFT('beijing2008',7),LEFT('beijing',null),RIGHT('beijing2008',4);

5. lpad(str,n,pad) and rpad(str,n,pad) functions:

Fill the leftmost (right) side of the string str with the string pad, knowing that the length is n characters long

 SELECT LEFT('beijing2008',7),LEFT('beijing',null),RIGHT('beijing2008',4);

6. ltrim(str) and rtrim(str) functions:

Remove spaces from the left or right of the string str

 select ltrim('  |beijing'),rtrim('beijing |     ');

 7. The repeat(str,x) function:

Returns the result of repeating str x times

select  repeat('mysql ',3);

 8. replace(str,a,b) function:

Replaces all occurrences of the string a in the string str with the string b

select replace('beijing_2010','_2010','2008');

9. trim (str) function:

Remove leading and trailing spaces from a string

 10. strcmp(s1, s2) function:

Compare the magnitude of the ASCII code value of the string s1.s2 (-1,0,1)

 select  strcmp('a','b'),strcmp('b','b'),strcmp('c','b');

 11. substring (str, x, y) function:

Returns a string of y characters long starting from position x of the string str

select substring('beijing2008',8,4),substring('beijing2008',1,7);

 

Guess you like

Origin blog.csdn.net/weixin_62190821/article/details/128468706