Redirect the output of a query in a file
18,285
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
Related videos on Youtube
Author by
Aomine Daiki
Updated on September 18, 2022Comments
-
Aomine Daiki over 1 year
What can I do to redirect the query result in a text file in
sqlplus
I tried:
start requete.sql > resultat.txt
but it doesn't work. -
apaul about 9 yearsI'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 thestart
or@
keywords:@/path/to/you/file.sql
-
Aomine Daiki about 9 yearsi have a problem spool dosen't work
-
apaul about 9 yearsImpossible. 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". -
Aomine Daiki about 9 yearsthis is the error:
SP2-0606: Cannot create SPOOL file "/resultat.txt"
-
apaul about 9 yearsIt cannot create the file because you try to write in the root (
/
). At this place, only the userroot
is allowed to create files and directories. Specify a path where your user has enough rights (in his home directory for instance)