Showing posts with label spool. Show all posts
Showing posts with label spool. Show all posts

Wednesday, October 02, 2013

SPOOL...APPEND

According to the book I found this in, it was new in Oracle 10 but I tested it on Oracle 11.2.0.2.7. You can SPOOL output to a file like this…
 
SQL> spool spool_test
SQL> select 'Andrew' Andrew from dual
  2  /
 
ANDREW
------
Andrew
 
SQL> spool off
 
…then you can run an OS command from within SQL*Plus to display the contents of the SPOOL file:
 
SQL> !cat spool_test.lst
SQL> select 'Andrew' Andrew from dual
  2  /
 
ANDREW
------
Andrew
 
SQL> spool off
 
If you repeat the SPOOL command and run some more SQL…
 
SQL> spool spool_test
SQL> select 'Brian' Brian from dual
  2  /
 
BRIAN
-----
Brian
 
SQL> spool off
 
… the original contents of the output file will be overwritten:
 
SQL> !cat spool_test.lst
SQL> select 'Brian' Brian from dual
  2  /
 
BRIAN
-----
Brian
 
SQL> spool off
 
But if you add the word APPEND to the end of the SPOOL command and run some more SQL…
 
SQL> spool spool_test append
SQL> select 'Colin' Colin from dual
  2  /
 
COLIN
-----
Colin
 
SQL> spool off
 
…the new output is added to the end of the output file:
 
SQL> !cat spool_test.lst
SQL> select 'Brian' Brian from dual
  2  /
 
BRIAN
-----
Brian
 
SQL> spool off
SQL> select 'Colin' Colin from dual
  2  /
 
COLIN
-----
Colin
 
SQL> spool off

Friday, July 13, 2012

ORA-00932

This was tested on Oracle 9 and Oracle 11.2. If you are searching for a piece of text, which you believe is in one of your views, you might try to do it like this:

SQL> select owner, view_name
  2  from dba_views
  3  where upper(text) like '%BLAH%'
  4  /
where upper(text) like '%BLAH%'
            *
ERROR at line 3:
ORA-00932: inconsistent datatypes: expected NUMBER got
LONG

SQL>

It fails because TEXT is a LONG column:

SQL> desc dba_views
Name                       Null?    Type
-------------------------- -------- ------------------
OWNER                      NOT NULL VARCHAR2(30)
VIEW_NAME                  NOT NULL VARCHAR2(30)
TEXT_LENGTH                         NUMBER
TEXT                                LONG
TYPE_TEXT_LENGTH                    NUMBER
TYPE_TEXT                           VARCHAR2(4000)
OID_TEXT_LENGTH                     NUMBER
OID_TEXT                            VARCHAR2(4000)
VIEW_TYPE_OWNER                     VARCHAR2(30)
VIEW_TYPE                           VARCHAR2(30)
SUPERVIEW_NAME                      VARCHAR2(30)

SQL>

One workaround is to SELECT the OWNER, VIEW_NAME and TEXT of all your views and SPOOL them to a file. Then you can search the spool file produced with vi or Notepad.