| |
|
If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
|
 |

01-10-06, 07:08
|
|
Registered User
|
|
Join Date: Jan 2006
Posts: 9
|
|
|
Spool file?
|
|
Hi there,
I have a query that I would like to automate: not only the query itself but also the results. I think this can be done by creating a spool file?
|
|

01-10-06, 08:04
|
|
Lost Boy
|
|
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
|
|
Yes, query results can be spooled into a file.
But, until you tell us which DB you use, it is hard to tell the correct answer.
|
|

01-10-06, 08:17
|
|
Registered User
|
|
Join Date: Jan 2006
Posts: 9
|
|
|
|
Ok, I use Toad en SQL*PLus on Oracle databases.
What I would like, is the following:
I have already designed a query, that produces (on screen, not in a table) the number of customers per month.
I would like to automatically run this query without manually starting Toad and/or SQL*Plus and to save the results in a txt file on my c drive.
|
|

01-10-06, 08:49
|
|
Lost Boy
|
|
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
|
|
To run the script automatically, use some kind of a scheduler on your computer (MS Windows, for example, offer "Scheduled tasks" under Accessories - System tools). I'm not sure can it be done through TOAD (but I'd bet NO if you ask me), but I'm sure it CAN be done in SQL*Plus.
Spooling in Oracle can be done using SPOOL command in SQL*Plus. A very simple SQL script example would be this:
spool output.txt
select * from emp;
spool off;
|
|

01-10-06, 09:18
|
|
Registered User
|
|
Join Date: Jan 2006
Posts: 9
|
|
Ok, so I can give my script - including the spool command - a name and save it as e.g. c:/test.sql.
How do I than schedule it via MS Windows? The wizard talks about the application to select (here,SQL Plus), but how does Windows know that it only shoudl run my c:test.sql??
|
|

01-10-06, 12:32
|
|
Lost Boy
|
|
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
|
|
|
|

01-11-06, 02:35
|
|
Registered User
|
|
Join Date: Jan 2006
Posts: 9
|
|
You have to help me here...
This is my query:
SET TERMOUT OFF;
SET ECHO OFF;
SPOOL c:/test.txt
select to_char(a.day_of_creation,'yyyy-mm') as month,count(distinct a.customer_accountno) as aantal
from ecl_cases a
where a.CASE_TYPE<>'BLOKSTORINGEN'
and (to_char(a.DAY_OF_CREATION,'yyyy-mm-dd')>='2004-10-01' and to_char(a.DAY_OF_CREATION,'yyyy-mm-dd')<='2004-12-31')
group by to_char(a.day_of_creation,'yyyy-mm')
order by to_char(a.day_of_creation,'yyyy-mm') asc;
SPOOL OFF;
I have saved this as test.sql
So, now I would like to only double-click on this file in Windows explorer to run it. So, without starting SQL*Plus myself. What should I do than?
|
|

01-11-06, 02:43
|
|
Registered User
|
|
Join Date: Jan 2006
Posts: 9
|
|
I tried your bat file option, but the MS-DOS screen gives:
ORA-12560: TNS: protocol adapter error
Do I have to put the database-name (server) aslo in the bat.file?
|
|

01-11-06, 04:09
|
|
Lost Boy
|
|
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
|
|
For example, those two files might look like below. You would double click on P.BAT file to run P.SQL file and have output stored in P.TXT file.
REM P.SQL FILE
spool p.txt
select count(*) from tab;
spool off;
exit;
REM P.BAT FILE
sqplus -s username/password@database @p.sql
|
|

01-11-06, 04:23
|
|
Registered User
|
|
Join Date: Jan 2006
Posts: 9
|
|
Yep, it works! Great, thanx for all your help!
|
|

01-11-06, 07:16
|
|
Lost Boy
|
|
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
|
|
No problem, I'm glad you've made it.
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|