-4

I need to run SQL query saved in test.sql file from bash script. Bash script will be run from a linux server that is also running SQL*Plus which connect to database server.in addition, generated output of this query should be csv format and saved into linux server e,g /data/test.csv. Can somebody help me out?

Thanks, Sam

1

wrapper.sql:

set echo off
set markup csv on
spool /data/test.csv
@/path/to/test.sql
spool off
exit

Command to invoke from script:

sqlplus -S user/password@TNS @wrapper.sql

  • I am getting an error SPOOL command not found, though i entered export ORACLE_HOME, export ORACLE_SID and export ORACLE_BIN values into the bash script – sam Jan 10 at 23:31
  • Regarding error SPOOL command not found, it sounds like you entered the spool as part of the shell script, not the sql script. We can only guess because you don't show your code. – EdStevens Jan 11 at 1:44
  • Worked. Thanks! Only thing i need to address now is to how to hide csv data from appearing on the screen. – sam Jan 12 at 0:57
  • I need to create directory with date stamp . Is there a command that can create a directory with current date in SQLplus? – sam Feb 1 at 23:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.