how can we write a column values horizontal by using sql stmt;
ex:
select name from table_name;(actual output)
a
b
c
d
require output is
a b c d

Answer Posted / pankaj goyal

SQL wm_concat function
Question: I have a table test_test and I need to count the
distinct mark columns and them display all matching values
on one line:

Name Mark
------- ------
ABC 10
DEF 10
GHI 10
JKL 20
MNO 20
PQR 30

The result should be like this, with the count and the rows
groups onto the same line;

mark count names
---- ----- -----------
10 3 ABC,DEF,GHI
20 2 JKL,MNO
30 1 PQR




Answer: By Laurent Schneider: You could write your own
aggregate function or use WM_CONCAT:

select
mark,
count(*),
wm_concat(name)
from
test_test
group by
mark;

Here is another example of using wm_contcat:

select
deptno,
wm_concat(distinct ename)
from
emp
group by
deptno;


DEPTNO WM_CONCAT(DISTINCTENAME)
---------- ----------------------------------------
10 CLARK,KING,MILLER
20 ADAMS,FORD,JONES,SCOTT,SMITH
30 ALLEN,BLAKE,JAMES,MARTIN,TURNER,WARD

Is This Answer Correct ?    9 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Show how functions and procedures are called in a pl/sql block.

679


What do you mean by rowid?

617


how can we optimize or increase the speed of a mysql select query? : Sql dba

594


What is sqlerrm?

631


What is a table in a database?

665






Mention what are different methods to trace the pl/sql code?

651


Is sqlexception checked or unchecked?

632


What is a ddl command?

622


How would you convert date into julian date format?

706


What is meant by truncate in sql?

629


What is database sql?

625


What is data control language?

634


Does pl sql work in mysql?

618


What does the acronym acid stand for in database management?

672


what is cross join? : Sql dba

656