Oracle 10g - Write queries results to file

て烟熏妆下的殇ゞ 提交于 2019-12-10 13:01:11

问题


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:


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/password@database.domain.com < tmp.sql > output.txt

4 - Look inside "output.txt"




回答2:


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




回答3:


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


来源:https://stackoverflow.com/questions/2299375/oracle-10g-write-queries-results-to-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!