Hello, you are not logged in.  Login or sign up
Community >> Blogs
Search Toad World Search

Blogs
Toad and Database Commentaries

 Toad World blogs are a mix of insightful how-tos from Quest experts as well as their commentary on experiences with new database technologies.

Do you have a topic that you'd like discussed?  We'd love to hear from you.  Send us your idea for a blog topic.

Toad Executing Scripts against Multiple Databases (Part 3)
 
Location: Blogs Bert Scalzo's Blog    
 Bert Wednesday, August 13, 2008 7:18 AM
Last week’s blog was the second in a series about how to make Toad run scripts or commands against multiple databases at once. Lots of people did not know that there are multiple ways in Toad to do this. This week I’ll highlight the third method of running scripts against multiple databases using the “Toad Editor” and Dynamic SQL Scripting. This week’s method is neither the easiest nor the best, it’s just yet another way to accomplish this task. It also has the benefit of building on one of my earlier blogs about Dynamic SQL Scripting via Toad. Furthermore, it starts us thinking about the problem in terms of its atomic operations – which will nicely lead us into next week’s fourth method (i.e. Toad Actions and Application Designer – the replacement for the older Toad Command Line facility). So please read on.
 
I have the Dynamic SQL script (shown here) which I use to coalesce all the tablespaces in the current database. If I load this script into the Toad Editor and press F5 (Execute Script), it will coalesce all the tablespaces in that session’s database – and only that database. There’s nothing too fancy here.
set term off
set pagesize 0
set verify off
set feedback off
spool coalesce.tmp
select 'alter tablespace '||tablespace_name||' coalesce;'
 from dba_tablespaces
 where status = 'ONLINE'
    and contents not in ('TEMPORARY','UNDO');
spool off
set term on
set echo on
@coalesce.tmp
Now what if I want to run this script against multiple databases? Well, I can simply use the exact same technique (Dynamic SQL) that now calls another Dynamic SQL script to get Toad to run the commands against multiple databases. Look at the script below in Toad’s Editor and the resulting output – mission accomplished! So just what did I do here? I merely wrote a Dynamic SQL script that calls the coalesce.sql script for the hard-coded databases. And yes, I know using SYSTEM is a bad practice, as is hard coding the user id and password. But I wanted to show this first. A slightly better method will be shown later.
 

  
The slightly better (i.e. more secure) solution is slightly more complex – but also happens to be much easier to dynamically make work for any number of databases without making any code modifications.
set term off
set pagesize 0
set verify off
set feedback off
spool c:\temp\coalesce_all.tmp
select 'spool c:\temp\coalesce_all.log' from dual;
select 'connect ‘||SYS_UID||’/’||SYS_PWD||'@’||DB_SID||’
'||'@coalesce.sql'
From berts_system_user_id_table;
select 'spool off' from dual;
spool off
@c:\temp\coalesce_all.tmp
Remember – in the weeks to come I’m going to demonstrate other ways to execute SQL scripts against multiple databases at once, so please continue to tune in  
Permalink |  Trackback

Comment:
Add Comment   Cancel 
Search Blog Entries
 
Blogger and Topic List
 

 

All Recent Entries
 

 

Johannes Ahrends
Unicode

Steven Feuerstein
Oracle PL/SQL

Daniel Norwood
Toad for Data Analysts
John Pocknell
Toad for Oracle
Bert Scalzo
Toad for Oracle, Data Modeling, Benchmarking
Jeff Smith
Toad product family
Richard To
SQL Optimization
Jim Wankowski
DB2 - LUW and z/OS
John Weathington
Compliance
Doug Williams
Database Musings
  Henrik "Mauritz" Johnson
Toad Tips & Tricks on the "other" Toads
  Toad World Editor
Toad World issues

  Toad Data Modeler Opens in a new window
Data Modeling
 

Copyright 2008 by Quest Software  | Terms Of Use | Privacy Statement | Contact Us