Link to home
Start Free TrialLog in
Avatar of Pau Lo
Pau Lo

asked on

query tools

what tools on windows server (with oracle installed) do you typically use to run SQL queries against a database? And what do you refer to the query tools/software as? And if you have a huge batch of seperate SELECT type queries, that you want to run in one swoop, as opposed to one after the other, how do you go about this in oracle query tools? Can you add a number of queries into a script to run all at once, or how would you approach this?
ASKER CERTIFIED SOLUTION
Avatar of David VanZandt
David VanZandt
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Pau Lo
Pau Lo

ASKER

they are basically just queries to list security settings and general configurations about the database(s), which only need to be run once every 3 months. Non of them are doing anything but extracting settings, i.e. no updates etc. Output format ideally csv, html, or text file, something along those lines. I used command prompt commands quite regulalrly which has an export feature i.e. "> filename.txt"
For non-interactive tasks dbms_scheduler, sqlplus and PowerShell are the way to go IMHO. PS works great if you need more advanced formatting, but HTML (which I would prefer here) can be generated by PS and sqlplus. PS has the additional advantage that sending results as mail is a piece of cake.
Avatar of Pau Lo

ASKER

can you give a bit of a beginners guide to running multiple queries in one go using sqlplus.

also is sqlplus something you get and install on oracle db servers with linux/unix type OS.
SQL*Plus is included in both server and client software installations, independent from OS.

With a SQL batch for reporting, the issue isn't usually to run more than one SQL statement, but to do so with proper formatting, as you usually create different tables with different layout.

There are several ways to active HTML reporting in sqlplus (which I recommend to use). You can either tell the sqlplus call on commandline to generate HTML, and to store into a file, or do that inside of the script. I'll show the "all-in-one script" way:
set MARKUP HTML ON SPOOL on
spool 'report.html'
select a, b, c from tbl1;
select e, f from tbl2;
-- and so on
spool off

Open in new window

Name that report.sql and call it with
sqplus usr/pwd@tns -silent -restrict @report.sql

Open in new window

Avatar of Pau Lo

ASKER

so all results will end up in a single html report? how would you diffrentiate between the results/output, i.e. which rows are from which query, .....or is it one html report per query?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I expected you to want a single file containing all reports, and the results being obvious. Just try if the result file meets your needs.

If you want to have different files for each table, just insert a
spool off
spool 'DifferentFile.html'

Open in new window

with a changing file name, of course, between each SQL statement.
A supplement to Qlemo's prior post, SPOOL cannot be nested.