Solved

query tools

Posted on 2014-01-06
10
371 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 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).
0
 
LVL 68

Assisted Solution

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

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 68

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 36

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

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 68

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now