Tuesday, May 18, 2010

Spooling

One of the things I thought was the coolest when I was just starting to learn SQL was the idea of using SQL queries to generate scripts. Sometimes you use this ability in some kind of a GUI and sometimes you spool the output into a file which you later on run as a script (SQL, cmd, etc.). When you spool into a script file you often need to have control on the output formatting - remove "x rows selected" lines and the kind - so that you script executes as intended. To achieve this there are many SQLPlus commands like:
set feedback on\off
set heading on\off
set echo on\off
...
But it seems there's a catch, I wasn't able to determine if this is the expected behavior or just some weird bug, but a while ago we had a problem with an SQL generated script and when we tried to debug it, it seemed like none of the above commands had any effect!
(Unfortunately) I was unable to find the site that helped us to solve the case, but apparently, to function those commands need to be run as part of a script and not from the SQLPlus prompt.