Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 432
  • Last Modified:

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?
0
pma111
Asked:
pma111
  • 4
  • 3
  • 2
  • +1
3 Solutions
 
DavidSenior Oracle Database AdministratorCommented:
It depends.  As a back-end user (DBA, developer, architect, etc.) the power tools are Quest's TOAD, Oracle's (FREE) SQL*Developer, and SQL*Plus for a client-host command line.

Regarding the "huge batch", the traditional approach was to script in SQL*Plus, but to execute those jobs through the OS, with shell or batch wrappers.  Since 10g, the go-to best approach IMO is Oracle's built-in dbms_scheduler. It's nicely matured, versatile, and easy to use in the Enterprise Manager/Grid Control -- if you need that level of horsepower.

One or many, again, it depends.  I would suggest you say more about the queries' purpose, the frequency, the volume of the data, and the required format of the results.  With the job scheduler I might turn them all loose at a given time, but to throttle the load with a queue limit (say, ten queries at a time).
0
 
QlemoC++ DeveloperCommented:
I don't agree to the dbms_scheduler point. It's useful if you have to do the same job regularily for the same database (schema or instance).
For automated or semi-automated or manual stuff I'm still preferring SQL*Plus - or the much more useful and advanced PowerShell, if on Windows. The latter works great if there is a need for particular data processing on the client side, as coding that is easier to implement and debug. But that's for a different level of demand than the usual tasks.

Other than that, I use free tools, like Database Browser and SQL*Developer. But that really depends on what I want to do.
0
 
pma111Author Commented:
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"
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
QlemoC++ DeveloperCommented:
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.
0
 
pma111Author Commented:
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.
0
 
QlemoC++ DeveloperCommented:
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

0
 
pma111Author Commented:
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?
0
 
Geert GruwezOracle dbaCommented:
i use toad/sqlplus for general
if i have to run queries on multiple db and get feedback
i create the query in a file and the list of databases in another, then use batch processing
i only work on windows atm
the script folder contains 2 subfolders: queries and data

sample:
query 2 databases for disabled triggers

the basic script to start: triggers.cmd
run_query db_prd.txt queries\triggers.sql data\triggers.txt
echo. finished at %date% %time%
pause 

Open in new window


file: db_prd.txt
this contains items to create the connection string alias:oracle_sid:syspassword:Y
Y or N at the end to run the query on the DB or not
db1_prd:db1p11:password:Y
db2_prd:db2p11:password:Y

Open in new window


the queries\triggers.qry
select table_owner, table_name, trigger_name, trigger_type, status from dba_triggers t
where status <> 'ENABLED';

Open in new window


run_query.cmd
rem @echo off
set dbfile=%1
set qryfile=%2
set expfile=%3

if not defined dbfile set dbfile=db_prd.txt
if not defined qryfile set qryfile=queries\query.sql
if not defined expfile set expfile=data\data.txt

set tns_admin=\\tnslocation\tnsnames

set tmpqryfile=%qryfile%.tmp.qry

(
echo.define destfile=^&1
echo.set linesize 9999, pagesize ^0, verify off, wrap off, feedback off, COLSEP ^|, echo off
echo.set termout off, trim on, tab off, trimout on trimspool on, serveroutput on
echo.whenever sqlerror exit;
echo.spool ^&destfile. APPEND
) > %tmpqryfile%
type %qryfile% >>%tmpqryfile%
echo.spool off >>%tmpqryfile%
echo.exit >>%tmpqryfile%
echo.Query for all db: %qryfile%>%expfile%
for /f "usebackq tokens=1,2,3 delims=:" %%G in (`findstr ":Y" %dbfile%`) do (
  echo.Running query on %%G
  echo.database %%G>>%expfile% 
  sqlplus -L "sys/%%I%%H@%%G as sysdba" @%tmpqryfile% %expfile%
  echo.-------------------->>%expfile%
)
pause

Open in new window


the weak point, as usual, is the password passing and storing it
0
 
QlemoC++ DeveloperCommented:
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.
0
 
DavidSenior Oracle Database AdministratorCommented:
A supplement to Qlemo's prior post, SPOOL cannot be nested.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now