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
Piping output of "top" to a text file safraser UNIX for Dummies Questions & Answers 13 05-21-2009 05:13 PM
piping output of tail running in background anuramdas Shell Programming and Scripting 4 07-27-2007 03:20 PM
piping output to echo A1977 Shell Programming and Scripting 3 11-01-2006 08:58 AM
piping the output of find command to grep 435 Gavea UNIX for Dummies Questions & Answers 1 10-05-2006 05:48 PM
Piping output to while read Ultimodiablo Shell Programming and Scripting 3 11-26-2005 10:38 PM

Closed Thread
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 07-23-2006
satnamx satnamx is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 34
piping oracle output to a file?

Hi All...

Does anyone know how to pipe the output of a "select" statement from a call to Oracle to a file?

ANy ideas woule be greatly appreciated!

Code is as below...

echo "producing CSV file 2..."
sqlplus -s $username/$password@$database<<EOF

set serveroutput on size 1000000
set verify off
set feedback off
set pagesize 0
VARIABLE vi_err NUMBER

SELECT empno||','||ename||','||job||','||mgr||hiredate||','||sal||','||comm||','||deptno FROM emp;
EXIT:vi_err
EOF
  #2 (permalink)  
Old 07-24-2006
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
spool

Why dont you spool the output to a file
Code:
set serveroutput on size 1000000
set verify off
set feedback off
set pagesize 0
spool filename
VARIABLE vi_err NUMBER

SELECT empno||','||ename||','||job||','||mgr||hiredate||','||sal||','||comm||','||deptno FROM emp;
spool off
EXIT:vi_err
EOF
  #3 (permalink)  
Old 07-24-2006
Dhruva's Avatar
Dhruva Dhruva is offline
Registered User
  
 

Join Date: Mar 2006
Location: India
Posts: 255
If you want to use redirection to a file ..try this.Now testing.dat will have the sql output.

X=`sqlplus -s user/pwd@host<<eof
set serveroutput on;
set feedback off;
set linesize 1000;
select * from table where rownum<5;
EXIT;
eof`

echo $X>testing.dat
  #4 (permalink)  
Old 07-24-2006
satnamx satnamx is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 34
Thanks!

Cheers lads! v useful tips.

I also found another way... as below.

{
echo "set pagesize 0"
echo "SELECT empno||','||ename||','||job||','||mgr||hiredate||','||sal||','||comm||','||deptno "\
"FROM emp;"
} | sqlplus -s $username/$password@$database >> $root_dir/$csv_file1

Kind Regards

Satnam
  #5 (permalink)  
Old 07-28-2006
ragha81 ragha81 is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 145
hi satnam.. is there a way not to mention the user name and pasword in the script. i have a requirement like this. i have to run a sql query using shell scripts. once the query is run, the results have to be stored in a data file. if any values are returned by the query, it should display an error msg to the user or else it has to exit. pls help me with this as i am totally new to shell scripting and i just started to learn..
  #6 (permalink)  
Old 03-17-2008
gauravah gauravah is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 2
Quote:
Originally Posted by Dhruva View Post
If you want to use redirection to a file ..try this.Now testing.dat will have the sql output.

X=`sqlplus -s user/pwd@host<<eof
set serveroutput on;
set feedback off;
set linesize 1000;
select * from table where rownum<5;
EXIT;
eof`

echo $X>testing.dat

hi, I am new to unix I have executed the following script :-

X=`sqlplus service/service@psmf.world <<eof
set serveroutput on;
set feedback off;
set linesize 1000;
select count(*) from table ;
EXIT;
eof`

echo $X>testing1.txt

.... and got the following output

vi testing1.txt
SQL*Plus: Release 9.2.0.5.0 - Production on Mon Mar 17 07:57:45 2008

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.


Connected to:
Oracle9i Enterprise Edition Release 9.2.0.5.0 - 64bit Production
With the Partitioning option
JServer Release 9.2.0.5.0 - Production

SQL>
COUNT(*)
----------
270

SQL> Disconnected from Oracle9i Enterprise Edition Release 9.2.0.5.0 - 64bit Production
With the Partitioning option
JServer Release 9.2.0.5.0 - Production


I only want output 270 in the file. How can i get this output? Please give your inputs
  #7 (permalink)  
Old 03-17-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,312
If you have questions do not hesitate to ask but start your own thread and don't hijack old threads.
Having said that, with awk you can get the value as follow:

Code:
awk '/----.*/{getline;print;exit}' testing1.txt
Regards
Closed Thread

Bookmarks

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 09:00 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