?
Solved

query tools

Posted on 2014-01-06
10
Medium Priority
?
433 Views
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?
0
Comment
Question by:pma111
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 23

Accepted Solution

by:
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).
0
 
LVL 72

Assisted Solution

by:Qlemo
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.
0
 
LVL 3

Author Comment

by:pma111
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"
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LVL 72

Expert Comment

by:Qlemo
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.
0
 
LVL 3

Author Comment

by:pma111
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.
0
 
LVL 72

Expert Comment

by:Qlemo
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:
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
 
LVL 3

Author Comment

by:pma111
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?
0
 
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

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
 
LVL 72

Expert Comment

by:Qlemo
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.
0
 
LVL 23

Expert Comment

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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

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

Exchange database can often fail to mount thereby halting the work of all users connected to it. Finding out why database isn’t mounting is crucial and getting the server back online. Stellar Phoenix Mailbox Exchange Recovery is a champion product t…
If you try to migrate from Elastix to Issabel, you will face a lot of issues. These problems are inevitable but fortunately, you can fix them. In the guide below, I will explain how I performed the migration while keeping all data and successfully t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

593 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