views:

62

answers:

3

Hello,

I want to run 200+ select queries and append the results to a file. All queries are the same the only difference in the date-time variable. I don't have privileges to create a routine that's why I had to create all the queries. I don't have privileges to create a view or another table to store the results in. I don't have access to PL/SQL.

Now I need to create a report with the results of each one of this queries (all results are integer numbers) but I don't seem to find another solution but to run one by one and copy the results one by one.

Any of you marvelous brains can give me a hand on this? It's kind of urgent.

+1  A: 

You can spool your output to a file.

See the spool (URL - Oracle 10.2 user's guide) command.

Also:

http://www.praetoriate.com/t_garmany_easysql_the_spool_command.htm

And what appears to be some layout tips:

http://www.oracle.com/technology/oramag/code/tips2004/020904.html

FrustratedWithFormsDesigner
Already tried that and it didn't work quite well. It stores the query string and also, it kind of breaks if I run 10 queries at the same time.
Daniel
try `set echo off;` before running the query. That prevent the query string from being displayed.Of course, of `echo` was on at the begining of the script, be sure to turn it back on at the end. Always leave things in the state you found them ;)
FrustratedWithFormsDesigner
Will try that one.
Daniel
+1  A: 

1 - Put your queries in a text file like so:

set pagesize 0;

select some_field
from some_table;

select another_field
from another_table;
/

2 - Save it somewhere (let's say c:\my_file.sql)

3 - Run this at the command prompt:

c:\>sqlplus -s username/[email protected] < tmp.sql > output.txt

4 - Look inside "output.txt"

JosephStyons
He'd still have to `set echo off;` though, wouldn't he? Otherwise, wouldn't the query string be in the output?
FrustratedWithFormsDesigner
Excellent Joseph. Will try this one too. Thank you!!
Daniel
Although the query is not in the output, the column name is. Is there a way of get ride of it??
Daniel
@Daniel; I modified my example with the "set pagesize 0" command, which will suppress column headers. I also added the "-s" argument, which suppresses the sql plus intro banner.
JosephStyons
A: 

If you have access to sqlplus, you can run anonymous PL/SQL blocks.

DECLARE
 v_cnt number;
BEGIN
 select ... into v_cnt ...;
 dbms_output.put_line(v_cnt);
END;
.
spool out.log
/
spool off
Gary