query tools

Posted on 2014-01-06
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
  • 4
  • 3
  • 2
  • +1
LVL 23

Accepted Solution

David earned 167 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 69

Assisted Solution

Qlemo earned 167 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"
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

LVL 69

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 69

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 37

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 166 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 69

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Powershell script 13 102
How to free up undo space? 3 41
Oracle DB monitor SW 21 49
Not able to drop or recreate an Oracle stored procedure 1 31
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Creating and Managing Databases with phpMyAdmin in cPanel.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

810 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