Taken in the positioning of characters mysql

Common clipping function
length - calculated length of the string
concat - connecting the two strings
substring - interception string
floor / ceil - ... mathematical function

select length('2340');
--->4
select length(2340);
--->4
select length('2019-09-01');
--->10
select length(2019-09-01);
--->4

select concat('1','1');
--->11
select concat(1,1);
--->11
select concat('2019-09-01','2019-09-02');
--->2019-09-012019-09-02
select concat(2019-09-02,2019-09-02);
--->20082008
select concat('a','a');
--->aa
select concat('a ','a');
--->a a

SELECT SUBSTRING ( 'computer', 3 ) AS col1, # a first position. 1
the SUBSTRING ( 'Computer', 3,4-) col2 the AS,
the SUBSTRING ( 'Computer', -. 3) col3 the AS,
the SUBSTRING ( 'Computer', -5,3) AS col4;

Returns substring col1 from the first position to the 3 end of the string, the result is "mputer"
col2 returned from the third start position substring of length 4, the result is "the mput";
col3 returned from the penultimate 3 substring positions to the end of the string, the result is "TER";
COL4 returned from the start position of the penultimate 5 substring of length 3, the result is a "put".

select floor (100.1); #floor function returns the largest integer less than or equal to the value (rounded down).
---> 100
SELECT Floor ( '100.1');
---> 100
SELECT Floor (-100.1);
- -> --101

select ceil (100.1); # rounding up
---> 101
SELECT ceil (-100.1);
---> - 100

select round (15.4) # rounding

select round (15.5) # rounding

select left ( '2019-08-01 00: 00 : 00', 4); # is the first position. 1
-> 2019
SELECT MID ( '2019-08-01 00: 00: 00', 6,2) ;
-> 08
SELECT right ( '2019-08-01 00: 00: 00', 2);
-> 00

SUBSTRING_INDEX (STR, the delim, COUNT)
STR: the string to be processed
delim: Separator
count: Count

str = www.wikibt.com

substring_index(str,'.',1)
--->www
substring_index(str,'.',2)
--->www.wikibt

That is, if the count is positive, then that is from left to right, the entire contents of the N-th separator left the
contrary, if it is negative, then it is from the right to left, all the contents to the right of the N-th delimiter ,Such as:

substring_index(str,'.',-2)
--->wikibt.com

Some people may ask, wikibt if I want the middle of how to do?

Very simple, in two directions:

The second from the right to the right of all the separators, a first separator to the left and then from the left:

substring_index(substring_index(str,'.',-2),'.',1);
1
SUBSTR(str,num)
select SUBSTR('www.wikibt.com',5)
--->wikibt.com

select SUBSTR('www.wikibt.com',-5)
--->t.com

num> 0, the first num characters from the left to the right of the right
<0 when num, num from right to left several of the characters on the right

INSTR (STR, SUBSTR)
string STR searched
SUBSTR want to search for strings
Conclusion: STR string inside, the first position (INDEX) SUBSTR string appears, INDEX is calculated from the beginning of 1, if it is not found direct return 0, did not return a negative number.

- the presence of the query string:
the SELECT INSTR ( "ABCD", 'B');
---> 2

- a case where the query string does not exist:
the SELECT INSTR ( "ABCD", 'F')
---> 0

SUBSTR and INSTR
str = the WWW 23154
the SELECT substr (str, InStr (str, '
') +1)
1
2
combat
title contents
[Java3y simple joy of learning]
[] Java3y simple joy of learning slag slag
[Java3y learn simple easy to understand]
[ Java3y learn simple easy to understand] Barbara
[Java3y approachable] school bored
[beginner] Java3y boring school
[boring] Java3y beginners learn quack
[Java3y big data] pleased to learn
[learning] Java3y barabara school
[learning] barabara learn Java3y ha ha
[good] ameonna Java3y no melon learn
now I statistics appear inside the brackets [] frequency, for example: Java3y easy to understand how much the frequency of appearance.

select substring_index (left (title, INSTR (title, ' ]') -1), '[', -1),
the FROM xxx_table
. 1
2
seek current hour
select now ()

select mid(now(),12,2)

select SUBSTRING(now(),12,2)

select SUBSTRING_INDEX(now(),' ',-1)
select SUBSTRING_INDEX(SUBSTRING_INDEX(now(),' ',-1),':',1)

select SUBSTRING_INDEX(left(now(),instr(now(),':')-1),' ',-1)

Guess you like

Origin blog.51cto.com/14538264/2438836