How I can do to redirect the query result in a text file in sqlplus

I tried: start requete.sql > resultat.txt but it dosen't work


You are mixing shell and sqlplus commands. sqlplus doesn't understand redirections, you have to use the spool keyword.

For instance:

SQL> spool /tmp/result.txt
SQL> start requete.sql
SQL> spool off

From shell:

$ sqlplus scott/tiger @requete.sql > /tmp/result.txt
  • but how i find the file resultat:txt. i need an existing file not a temporary file – Aomine Daiki Apr 22 '15 at 11:22
  • I've written /tmp/result.txt but the path is up to you. Just replace /tmp/result.txt by /path/to/the/file/you/want.txt. It's the same for the start or @ keywords: @/path/to/you/file.sql – apaul Apr 22 '15 at 11:25
  • i have a problem spool dosen't work – Aomine Daiki Apr 22 '15 at 11:39
  • 1
    Impossible. Even if you specfied a path whose access is denied, you'd get an error. Note that when you use spool and specify no more options, the result of query is also displayed on your screen. You'll have to give more info than just "doesn't work". – apaul Apr 22 '15 at 11:47
  • 1
    It cannot create the file because you try to write in the root (/). At this place, only the user root is allowed to create files and directories. Specify a path where your user has enough rights (in his home directory for instance) – apaul Apr 22 '15 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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