|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Sponsored Links | |
|
|
|
#2
|
|||
|
|||
|
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 |
| Sponsored Links | ||
|
|
|
#3
|
||||
|
||||
|
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
|
|||
|
|||
|
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 |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
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..
|
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Please explain this code snippet to me
Hi all,
I am new to shell scripting and want to know how this code works. { 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 Thanks in advance. |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
Quote:
Code:
{
echo "...
} | sqlplusbasically collects all of the "echo" command's output as a group and they are piped through to Oracle's sqlplus command processor. So it behaves just like running sqlplus interactively and you typing in those commands. Code:
>> $root_dir/$csv_file1 directs the output from the SQL commands to a file on the UNIX server. The path and filename are in variables $root_dir and $csv_file. Ultimately, the SQL is building a csv (comma delimited) file that will be used for, presumably, as an input to another system. Thomas |
| Sponsored Links | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
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 04:13 PM |
| piping output of tail running in background | anuramdas | Shell Programming and Scripting | 4 | 07-27-2007 02:20 PM |
| piping output to echo | A1977 | Shell Programming and Scripting | 3 | 11-01-2006 07:58 AM |
| piping the output of find command to grep | 435 Gavea | UNIX for Dummies Questions & Answers | 1 | 10-05-2006 04:48 PM |
| Piping output to while read | Ultimodiablo | Shell Programming and Scripting | 3 | 11-26-2005 09:38 PM |
|
|