I want to spool the output from a .sql file to a .txt file through shell script.
the contents of .sql are:
spool /arboru02/scripts/customer_profile_def.txt
select profile_id ||','|| account_no
from customer_profile_def;
spool off
exit
and shell scrip is like:
#!/bin/sh
sqlplus 'username/pwd@instance'<<!
@/arboru02/scripts/customer_profile_def.sql>/arboru02/scripts/customer_profile_def.txt
exit
!
while executing the script im getting error unable to open file.
And please tell me what should be the path of the .sql and .txt files?
You are doing the same thing twice. Either you want "spool" to write directly to a file, or you want sqlplus to write to standard out for it to be redirected (> in the shell script). Doing both might be harmless in this case.
As for why it doesn't work, it's probably because the /scripts/ directory is not writable by you. The output should logically go somewhere else. Try /var/tmp/customer_profile_def.txt
That's a COMPLETELY different topic. It depends on the data, the output format, etc. I suggest you repost this one as a new thread, but add specifics like the file format and the fields you want to import into. (If a moderator flags you for this, refer them to this post).
I want to spool the output of query to a .txt file but when i am doing that along with the output of the query i am getting query itself and spool off in the output .txt file.
Plz tell me how can i just get the output of the query in the .txt file.
I'm not that familiar with oracle or sqlplus but if its the line with 'spool off' you don't want (or whatever line you don't want) to be in the output file then you may want to consider manipulating the output file a little like using sed to remove unnecessary lines
Have you tried using 'SET TERMOUT OFF' in your SQL?
(e.g.)
$ cat mysql.sql
SET FEEDBACK OFF
SET PAGESIZE 0
SET TERMOUT OFF
SPOOL testout.txt
SELECT SYSDATE FROM DUAL
/
From the SQLPLUS documentation:
SET TERMOUT
SET TERMOUT OFF suppresses the display so that
you can spool output from a script without seeing it on the screen.
If both spooling to file and writing to terminal are not required,
use SET TERMOUT OFF in SQL scripts to disable terminal output.