当前位置:网站首页>String function in MySQL

String function in MySQL

2022-04-23 17:56:00 Jian Xiaolin

1. About the length of the string

Code example :

select ascii('abc') ,char_length(' database '),length (' database ')
from dual;

ascii(s): Take the... Corresponding to the first place of the string ascii code

char_length(s): String length

length(s): Number of bytes of string

Running results :

2. String connection

Code example :

select concat(e.lie1,'worked for',m.lie1) 
from table e join table m
where e.lie3 =m.lie1 ;

concat : Connection of columns and strings , The specified string can be connected in the middle , As in the example above worked for.

3. String insertion and replacement

Code example :

select insert ('hello',2,3,'ddd'),replace ('hello','ll','oo')
from dual;

insert(a,b,c,d) In string a Of b Starting from , take b Go to b+c Replace with d.

replace(a,b,c) In the string b Replacing the c.

select left ('mysql',3)
from dual ;

left(a,b) Take the string a From left to front b A digital ,right Empathy .

Running results :

 

 4. Clean and double

Code example :

select trim('  my sql  ') ,trim('my'  from 'mysql') 
from dual;
select repeat ('mysql',2)
from dual ;

trim(a) Clear string a Spaces at both ends .

trim(a from b) eliminate b The... Contained in the string a character string .

repeat(a,b) The string a to b times .

Running results :

 

 5. Find the position of the string

Code example :

select elt(3,'a','b','c') ,field('my','sq','mysql','my'),find_in_set('my','m,my,mysql') 
from dual ;
select reverse('abc') 
from dual ;

elt(n,a,b,c...) from a Start looking for the second n Characters , Output this character .

field(n,a,b,c...)  from a Start looking for n, Output the number of its location .

reverse(s) Reverse output .

Running results :

 

版权声明
本文为[Jian Xiaolin]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231753567912.html