-1

I have a table employee having columns Name, Age, Department.

I need a query which produce output which concat values of Name , Age, Department as comma separated.

Query output should be like below :

ABC,23,Science
XYZ,34,Bio
QQQ,22,Account

I am not using stored procedure.

I search on internet and found concat function but looks like it wont work on multiple columns. Pls help considering i have 1-5 million records in table so need to look performance point as well.

VJS
  • 2,891
  • 7
  • 38
  • 70

1 Answers1

0

CONCAT doesn't behave nicely in this context as you have to nest several functions. But, the good, old double pipe concatenation operator || works well:

SQL> select ename ||','|| sal ||','|| job result
  2  from emp
  3  where rownum < 5;

RESULT
---------------------------------------------------
SMITH,1000,CLERK
ALLEN,1600,SALESMAN
WARD,1250,SALESMAN
JONES,2975,MANAGER

SQL>
Littlefoot
  • 131,892
  • 15
  • 35
  • 57
  • Thanks. How about the performance point of view if i have 1 million records..Any idea ? – VJS May 27 '20 at 11:21
  • It depends on what you want to do with that many rows. If you want to store the result into some table, it'll take some time (not because of concatenation, but because of data quantity). If you're about to run the query and stare at the screen as the results go by, it'll take even longer as *standard output* is slow. As I said: it is not about concatenation but data quantity. – Littlefoot May 27 '20 at 11:24