﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>FranklinFaces.com - Oracle &amp; SQL Server Database Forums for all IT Professionals / Oracle Forum / Oracle Database Administration  / Outputting Spool correct in oracle.  Spooling only results, spool output in oracle / Latest Posts</title><generator>InstantForum.NET v4.1.4</generator><description>FranklinFaces.com - Oracle &amp; SQL Server Database Forums for all IT Professionals</description><link>http://www.franklinfaces.com/</link><webMaster>no-reply@FranklinFaces.com</webMaster><lastBuildDate>Fri, 10 Feb 2012 23:38:14 GMT</lastBuildDate><ttl>20</ttl><item><title>Outputting Spool correct in oracle.  Spooling only results, spool output in oracle</title><link>http://www.franklinfaces.com/Topic170-97-1.aspx</link><description>I recently was in a process to create a script that rebuilds indexes on a weekly basis and I had a unix shell script that dynamically created the alter statements and spools it out to a file and then runs it.   I was trying to figure out how to spool only the results and stop the heading and feedbacks etc..   This is what I had and it kept on putting the sql statement and spool off in the spool file:&lt;/P&gt;&lt;P&gt;&lt;FONT color=#113311&gt;#!/usr/bin/ksh&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#113311&gt;. ~/.profile_PRODDB&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#113311&gt;echo $ORACLE_SID&lt;BR&gt;echo $ORACLE_HOME&lt;BR&gt;echo " "&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#113311&gt;$ORACLE_HOME/bin/sqlplus "/ as sysdba" &amp;lt;&amp;lt;EOF&lt;BR&gt;set feedback off&lt;BR&gt;set verify off&lt;BR&gt;set pagesize 0&lt;BR&gt;set term off&lt;BR&gt;set termout off&lt;BR&gt;set heading off&lt;BR&gt;set echo off&lt;BR&gt;spool rebuild_ecom_indexes.sql&lt;BR&gt;select 'alter index '||owner||'.'||index_name||' rebuild;' from dba_indexes where owner='ECOM' and TEMPORARY='N';&lt;BR&gt;spool off&lt;BR&gt;set timing on&lt;BR&gt;set term on&lt;BR&gt;spool /oracle/dba/scripts/logs/rebuild_indexes.log&lt;BR&gt;@rebuild_ecom_indexes.sql&lt;BR&gt;EOF&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;When I run this unix shell script it kept on putting the following in the rebuild_ecom_indexes.sql script:&lt;/P&gt;&lt;P&gt;&lt;FONT color=#113311&gt;&lt;FONT color=#ff1111&gt;SQL&amp;gt; select 'alter index '||owner||'.'||index_name||' rebuild;' from dba_indexes where owner='ECOM' and TEMPORARY='N';&lt;/FONT&gt;&lt;BR&gt;alter index ECOM.IDX$$_17CE30002 rebuild;&lt;BR&gt;alter index ECOM.SYS_C007048 rebuild;&lt;BR&gt;alter index ECOM.ADD_ARC_IDXSYSID rebuild;&lt;BR&gt;alter index ECOM.ADD_ARC_EXPORDERS2 rebuild;&lt;BR&gt;alter index ECOM.CUST_4413_5487__PRIMARYKEY rebuild;&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#ff1111&gt;SQL&amp;gt; spool off&lt;/FONT&gt;&lt;BR&gt;&lt;/P&gt;&lt;P&gt;I couldn't figure out why the item in red above kept coming into the spool file.   I had set the following in the script:&lt;/P&gt;&lt;P&gt;&lt;FONT color=#113311&gt;set feedback off&lt;BR&gt;set verify off&lt;BR&gt;set pagesize 0&lt;BR&gt;set term off&lt;BR&gt;set termout off&lt;BR&gt;set heading off&lt;BR&gt;set echo off&lt;/FONT&gt;&lt;BR&gt;&lt;/P&gt;&lt;P&gt;And still no good.  I started searching google and couldn't figure it out ... there were others looking for the same soultion and i found out that in the sqlplus command we need to issue a -s and it will stop the sql commands from being spooled out to the spool file.&lt;/P&gt;&lt;P&gt;So it should look like this:&lt;/P&gt;&lt;P&gt;$ORACLE_HOME/bin/sqlplus &lt;FONT color=#ff1111&gt;&lt;STRONG&gt;-s&lt;/STRONG&gt;&lt;/FONT&gt; "/ as sysdba" &amp;lt;&amp;lt;EOF&lt;BR&gt;set feedback off&lt;BR&gt;set verify off&lt;BR&gt;set pagesize 0&lt;BR&gt;set term off&lt;BR&gt;set termout off&lt;BR&gt;set heading off&lt;BR&gt;set echo off&lt;BR&gt;spool rebuild_ecom_indexes.sql&lt;BR&gt;select 'alter index '||owner||'.'||index_name||' rebuild;' from dba_indexes where owner='ECOM' and TEMPORARY='N';&lt;BR&gt;spool off&lt;BR&gt;set timing on&lt;BR&gt;set term on&lt;BR&gt;spool /oracle/dba/scripts/logs/rebuild_indexes.log&lt;BR&gt;-- @rebuild_ecom_indexes.sql&lt;BR&gt;EOF&lt;BR&gt;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;Good luck,&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;BR&gt; </description><pubDate>Wed, 09 Dec 2009 13:27:36 GMT</pubDate><dc:creator>Admin</dc:creator></item></channel></rss>
