0
votes

I'm using the spool command in sqlplus to generate a file with the rows of some queries.

First I assign an output format and secondly I do the spool to generate the output file, but it does not save all the rows.

set lines 100
set pages 1500
set colsep ';'
spool /home/bsoinst/users/example.txt

select name,salary from employees (query example)

The original query generates 1433 rows, but in the file it only shows 1414

Thanks

1
You ran the query to get 1433 rows and the spooled version in the same session? If so could committed changes have been made elsewhere in between; and if not were there uncommitted changes in one of the sessions? And are you sure it was exactly the same query - one wasn't distinct, or grouping differently, or something? - Alex Poole
Thanks for the reply. If the query was executed in the same session. I tried to execute the query from a file and it seems that a couple of rows appeared. - Jav
If you're still logged into that session, did you do spool off? If not everything you type now is still going into the file - but it's buffered so isn't written to disk immediately... - Alex Poole
Thanks for the answer, if it was that, I did not have the spool off. I have placed it and now if it keeps all the rows. - Jav

1 Answers

0
votes

Spool writes to a file, but the output is buffered. If you spool from an interactive session as you've shown then until you either exit the session or end the spool with spool off (or starting another spool) anything you do is still being written to the file, via the buffer.

SQL*Plus continues to spool information to the file until you turn spooling off...

Until the buffer is full, it won't be flushed to the filesystem. So if you look at the file it will be incomplete.

If you do:

spool off

then the remaining partial buffer will be flushed and the file will be closed, and will then be complete on the filesystem too. (You'll also now see anything you did between running the query and issuing that command, of course).

I believe the buffer size is operating-system/filesystem-dependent, and not something you can control from within SQL*Plus.