How can I write a query for below scenario in Oracle?
Input
Column1 Column2
R 1
S 2
F 3
Output
RSSFFF
i.e. 'R' 1 time, 'S' 2 time and 'F' 3 times.
How can I write a query for below scenario in Oracle?
Input
Column1 Column2
R 1
S 2
F 3
Output
RSSFFF
i.e. 'R' 1 time, 'S' 2 time and 'F' 3 times.
You can use rpad to repeat the letters, and listagg to concatenate them in a single line, like so.
select
listagg(rpad(column1,column2,column1)) within group (order by column2)
from table_name;
But this would work if you have another column to order the rows, in this case, I just use the column2.
order by clause, which would work without it.