- create statement
The create table car (
Name varchar2 (50), - type passenger cars
The conf varchar2 (50) - configuration instruction sheet
)
- insert test data
Insert into the car (the NAME, the CONF)
Values (' SUV ', 'part 1');
Insert into the car (the NAME, the CONF)
Values (' SUV ', '3 parts');
Insert into the car (the NAME, the CONF)
Values (' SUV ', 'parts 5');
Insert into the car (the NAME, the CONF)
Values (' cars' and 'part 1');
Insert into the car (the NAME, the CONF)
Values (' cars' and 'parts 3');
Insert into the car (the NAME, the CONF)
Values (' cars' and 'parts 5');
Insert into the car (the NAME, the CONF)
7 'values (' cars' and' parts);
Insert into the car (the NAME, the CONF)
Values (' police ', 'part 2');
Insert into the car (the NAME, the CONF)
Values (' police ', '3 parts');
Insert into the car (the NAME, the CONF)
Values (' police ', 'parts' 5');
Insert into the car (the NAME, the CONF)
Values (' police ', '7 parts');
2 - queries the effect of the source data such as illustrations expectation effect. JPG standard part of the need to pay attention to the red words
Select * from car order by name, substr (conf, 3, 1)
- the effect as expected
CodePudding user response:
If parts limited number and knowable, can do, we recommend baidu oracle longitudinal and transverseCodePudding user response:
Oracle LISTAGG a simple function,SELECT deptno, LISTAGG (ename, ', ') WITHIN GROUP (ORDER BY ename) AS employees
The FROM emp
GROUP BY deptno
The ORDER BY the deptno;
DEPTNO EMPLOYEES
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
10 CLARK, KING, MILLER
20 ADAMS, FORD, JONES, SCOTT, SMITH
30 ALLEN, BLAKE, JAMES MARTIN, TURNER, WARD
A detailed reference: "Oracle LISTAGG function explanation of his 19 c"