[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now


query tools

Posted on 2014-01-06
Medium Priority
Last Modified: 2014-01-13
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?
Question by:pma111
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
LVL 23

Accepted Solution

David earned 668 total points
ID: 39759006
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).
LVL 71

Assisted Solution

Qlemo earned 668 total points
ID: 39759038
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.

Author Comment

ID: 39759047
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"
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

LVL 71

Expert Comment

ID: 39759067
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.

Author Comment

ID: 39759073
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.
LVL 71

Expert Comment

ID: 39759146
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:
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


Author Comment

ID: 39759166
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?
LVL 38

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 664 total points
ID: 39759167
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

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%

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

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

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%

Open in new window

the weak point, as usual, is the password passing and storing it
LVL 71

Expert Comment

ID: 39759215
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.
LVL 23

Expert Comment

ID: 39759801
A supplement to Qlemo's prior post, SPOOL cannot be nested.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insiā€¦
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question