Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

Answers were Sorted based on User's Feedback



how can we write a column values horizontal by using sql stmt; ex: select name from table_name;(ac..

Answer / 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

how can we write a column values horizontal by using sql stmt; ex: select name from table_name;(ac..

Answer / ajit

select Replace ( Wm_concat( a ), ',' ) Actout
from Tablename;

Is This Answer Correct ?    0 Yes 0 No

how can we write a column values horizontal by using sql stmt; ex: select name from table_name;(ac..

Answer / ramaraju

select listagg(cust,' ') within group(order by cust) from t2;

Is This Answer Correct ?    0 Yes 0 No

how can we write a column values horizontal by using sql stmt; ex: select name from table_name;(ac..

Answer / prativa mishra

select xmlagg(xmlelement(g,column_name)).extract('//text()')
from table_name

Is This Answer Correct ?    0 Yes 2 No

how can we write a column values horizontal by using sql stmt; ex: select name from table_name;(ac..

Answer / kalaiselvi

select name from table_name order by name

Is This Answer Correct ?    1 Yes 12 No

Post New Answer

More SQL PLSQL Interview Questions

how to concatenate two character strings? : Sql dba

0 Answers  


how to calculate expressions with sql statements? : Sql dba

0 Answers  


overloading of stored procedure is possible in oracle?

3 Answers   Nelco,


cursor types? explain with example programs?

1 Answers   HP,


I have one table,in that table (1)i have java1.1 version books are 2 and java1.5 version books are 4. (2).Net2.0 books are 3, .Net3.5 books are 2 (3)ABC1.6 books are 4, ABC2.0 books are 3. Now i want output is like Book Count Java 6 .Net 5 ABC 7 For this i need sql query, please help me if anyone how to get this result. Thanks, Seenu

4 Answers   Adea,


how are mysql timestamps seen to a user? : Sql dba

0 Answers  


How do you delete data from a table?

0 Answers  


what is ref cursor in pl/sql?

3 Answers  


write an sql query to get third maximum salary of an employee from a table named employee_table. : Sql dba

0 Answers  


Give which cursor is better for better performance means type of cursors?

2 Answers  


What are the set operators in sql?

0 Answers  


How to place comments in pl/sql?

0 Answers  


Categories