Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 
 Home
 E-mail Us
 Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

 Applications
 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB  

Don Burleson Blog 


 

 

 


 

 

 

 
 

Display Oracle SQL output rows on one single line

Oracle Tips by Burleson Consulting


Question:  How to I get my SQL output rows to display on one line?

 
select ename from emp;

Smith
Jones
Baker
 
I want the SQL output on one line, like this:
 
select ename from emp;

Smith, Jones, Baker
 
How do I get multiple rows onto one line of output?
 
Answer: 
 
I have complete notes and samples of displaying multiple columns on a single row.
 
You can also use the undocumented SQL wm_concat function.
 
You can displaying multiple columns per row with sys_connect_by_path, or you can write a PL/SQL function to display multiple rows values on a single line. 
 
Also look at using Oracle analytics (the LAG and OVER functions) to display data in a single row of output.

Martin Chadderton has written a Pl/SQL function called "stragg" that you can define to display multiple SQL rows on one single line.  Once defined, you embed the function within your SQL to display your output on a single line:
select stragg(ename) from emp;

Smith, Jones, Baker

Sorting SQL output on a single line

Note that sorting is tricky, and even though the output displays on a single line, the "order by" does not sort the rows on the one line:

select stragg(ename) from emp order by ename;

Smith, Jones, Baker
The in-line view ensures that the SQL output appears sorted on one line of output:
select stragg(ename)
from
   (select stragg(ename) from emp order by ename);

Baker, Jones, Smith

 
 
If you like Oracle tuning, you may enjoy the new book "Oracle Tuning: The Definitive Reference", over 900 pages of BC's favorite tuning tips & scripts. 

You can buy it direct from the publisher for 30%-off and get instant access to the code depot of Oracle tuning scripts.


 

 

  

 
  
 
 
 

 
 
 

Oracle training Excel
 
Oracle performance tuning software 
 

 

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  and include the URL for the page.


                    









Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


 

Copyright ? 1996 -  2014

All rights reserved by Burleson

Oracle ? is the registered trademark of Oracle Corporation.