Question : Spool problem in sqlplus

Hello wizards!

I am experimenting with sqlplus and am trying to create a csv based on a query.

I have three problems though:

First of all, the query is always contained in the csv although I set the header option to off.
Secondly, the column separator option is not working at all and I don't want to neccessarily concatenate each column manually.

The third problem is that the spool doesn't quit automatically once the file has been written. I need to enter the console and carry out the command "spool off;" manually so I can access the csv afterwards.

I know these are many questions at once, but I'd be delighted if you could help me on that!

Brgds,

Seb
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
set termout off
set arraysize 5
set echo off
set verify off
set heading off 
set feedback off
set colsep ',';
set linesize 100
set pagesize 0
set sqlprompt ''
set trimspool on

define logname=date
column clogname new_value logname
select 'c:\temp\myexport'||to_char(sysdate, 'yyyymmdd') ||'.csv' clogname from dual;
spool '&logname'

select name,
       fallennr,
	   alf_login,
	   merkmal from (
select      to_number(b.lng_falle) lng_falle,
            to_date(b.date_datum) date_datum,
            to_number(b.int_fallennummer) int_fallennummer,
            to_number(b.kw) kw,
            to_number(b.lng_schaedling) schaedling,
            to_number(b.int_volumen) int_volumen,
            to_number(b.int_anzahl) int_anzahl,
            a.name,
            to_char(a.fallennr) fallennr,
            a.alf_login alf_login,
            a.merkmal
            from borki.vt_fangzahlen_tageswerte_2010 b
            inner join  borki.vt_fallenstandorte a on b.lng_falle =
            a.objectid
            where to_char(a.fallennr) = '28'
            and a.alf_login = 'ne'
            and b.date_datum >to_date('31.03.2007','DD.MM.YYYY'))
			group by name, fallennr, alf_login, merkmal
			order by name, fallennr;

spool off;

Answer : Spool problem in sqlplus

You can exeecute PL/SQL blocks in sql*plus you just can't use SQL*Plus specific commands in it.


UTL_FILE isn't that difficult and probably the correct way to go for your needs.  Once you get the PL/SQL written you can easily create a stored procedure and even schedule it to run at a specific time.

Check out:
http://psoug.org/snippet.htm/UTL_FILE_file_write_to_file_example_538.htm
Random Solutions  
 
programming4us programming4us