A, concat () function
1, mysql Concat function of one or more strings may be connected
select concat('10');//10
select concat('11','22','33');//112233
But Oracle's concat function can only concatenate two strings, no more and no less
select concat('11','22') from dual;
2, when the mysql Concat string reconnection function, as long as one is null, null is returned without South
select concat('11','22',null);//null
And when the concat function Oracle connection, as long as there is a string that is not NULL, NULL will not return
select concat('11',NULL) from dual;//11
Two, concat.ws () function
Represents concat with separator, that is the string concatenation delimiters
select concat_ws(',','11','22','33');//11,22,33
select concat_ws('|','11','22','33');//11|22|33
select concat_ws('*','11','22',NULL);//11*22
And concat difference is, concat_ws function when executed, will not return a NULL value NULL
三、group_concat()
* It must group by something sorted, printed out; otherwise, it does not work
Row column can be used to transfer
GROUP_CONCAT (Field [Order BY ASC / DESC sort field] [the DISTINCT] connected to [Separator 'delimiter'])
create table aa(
id int,
name VARCHAR(255)
);
insert into aa values(1,10);
insert into aa values(1,10);
insert into aa values(1,20);
insert into aa values(1,30);
insert into aa values(3,30);
insert into aa values(5,60);
insert into aa values(5,90);
insert into aa values(6,990);
Id packet 1, the value of the name field is printed on a line, separated by commas (default)
select id,group_concat(name) from aa group by id;
2 id packet, the value of the name field is printed on a line, separated by semicolons
select id,group_concat(name separator ';') from aa group by id;
3 id packet, the value of the name field of the redundancy elimination printed on a line, separated by commas
select id,group_concat(distinct name separator ';') from aa group by id;
4 id packet, the value of the name field is printed on a line, separated by *, to name row reverse
select id,group_concat(name order by name desc separator "*") from aa group by id
Four, repeat () function
To copy the string, as 'ab' represents a string to be copied, the copied parts 2 represents
select repeat('ab',2);//abab
select repeat('a',2);//aa
---------------------
forward from
Author: sink like a stone _wx
Source: CSDN
Original: https: //blog.csdn.net/vasilis_1/article/details/75305473