The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
select data from oracle table and save the output as csv file or .txt file in unix/solaris - script aemunathan Shell Programming and Scripting 4 2 Weeks Ago 10:13 PM
how to extract the data from database (oracle) and send the output as an .xls file? psiva_arul Shell Programming and Scripting 1 10-13-2009 01:58 PM
load a data from text file into a oracle table raji35 Shell Programming and Scripting 2 01-15-2009 03:48 AM
To load data from variable to oracle table ....??? Amit.Sagpariya Shell Programming and Scripting 2 12-15-2008 08:36 AM
To load data from variable to oracle table Amit.Sagpariya Shell Programming and Scripting 1 12-15-2008 07:20 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 2 Weeks Ago
rdhanek rdhanek is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 74
select data from oracle table and save the output as csv file

Hi

I need to execute a select statement in a solaris environment with oracle database. The select statement returns number of rows of data.

I need the data to be inserted into a CSV file with proper format. For that we normally use "You have to select all your columns as one big string, concatenating each column".
But my select query contains group by and order by functions using some alias names of the columns.
Can someone help me with the changes required to the sql query format to make sure that the data is inserted properly into csv file.

Code:
select
e.employee_name emp_name||'  ,'||
e.employee_address emp_add||'  ,'||
d.department_name dest_name
This is not working as there are some alias names for the columns.
  #2 (permalink)  
Old 2 Weeks Ago
panyam panyam is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Posts: 474
Better you can use the "set options" available with SQL*PLUS.

something like this :

Code:
set colsep=','
  #3 (permalink)  
Old 2 Weeks Ago
radoulov's Avatar
radoulov radoulov is online now Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,854
I think you need something like this:

Code:
select emp_name||'  ,'|| emp_add||'  ,'|| dest_name
  from ( 
    select 
      e.employee_name emp_name,
      e.employee_address emp_add,
      d.department_name dest_name
      ...


---------- Post updated at 09:35 AM ---------- Previous update was at 09:26 AM ----------

Quote:
Originally Posted by panyam View Post
Better you can use the "set options" available with SQL*PLUS.

something like this :

Code:
set colsep=','
With colsep the result will depend on linesize and the output could be different from what you expect:

Code:
SQL> set lines 132
SQL> set colsep ,
SQL> select ename name, customerid id from t;

NAME      ,        ID
----------,----------
name1     ,         1
name2     ,         2

SQL> select name||', '||id from (select ename name, customerid id from t);

NAME||','||ID
----------------------------------------------------
name1, 1
name2, 2

SQL> set lines 10
SQL> select ename name, customerid id from t;

NAME
----------
        ID
----------
name1
         1

name2
         2


SQL> select name||', '||id from (select ename name, customerid id from t);

NAME||','|
----------
name1, 1
name2, 2
Reply

Bookmarks

Tags
alias, format, sql output

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:34 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0