ba6.us - Dave's Database Related Stuff

  • home
  • blog
  • notebooks
  • projects
  • recent
  • about
  • manifesto
  • !
Home › Blogs › dmann's blog

Tag Cloud

apex Application Express Auditing data dbi development export funnies HTML Java linux monitoring oem oracle performance perl rman scripting sql SQL Developer sqlplus tuning unix windows
more tags

Search

RSS Feed

Blog Posts :

Navigation

  • Feed aggregator

User login

  • Request new password

Using SQLPLUS to generate scripts…

dmann — Thu, 08/10/2006 - 15:29

Tired of updating scripts by searching and replacing until your fingers fall off? Have a SQL statement you have to run against every table in your schema? Next to Regular Expressions, this is one of the most useful tools in my arsenal. Common uses for this are to write SQL statements that can work from a list of objects in the database: * Tables from USER_TABLES or DBA_TABLES * Constraints from USER_CONSTRAINTS or DBA_CONSTRAINTS * Indexes from USER_INDEXES or DBA_INDEXES * USER_OBJECTS with an appropriate filter on OBJECT_TYPE (TABLE, PACKAGE, SEQUENCE, etc…) Here is how to set up SQLPLUS script to generate a spool file that contains a list of generated SQL Statements: 1) Create a SQL scripts called genscript.sql with the following contents:
SET FEEDBACK OFF
SET HEADING OFF
SET LINESIZE 3800
SET PAGESIZE 0
SET SPACE 0
SET TERMOUT OFF
SET TRIMSPOOL ON
SPOOL c:\spool.sql
SELECT 'SELECT * FROM '||TABLE_NAME||' WHERE ROWNUM = 5;
2) Run the script:
SQLPLUS user/password@instance @genscript.sql
3) View your results:
EDIT c:\spool.sql
4) Run it!
SQL> @spool.sql
– Dave
  • oracle
  • sqlplus
  • dmann's blog

Post new comment

The content of this field is kept private and will not be shown publicly.
Input format
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
18 + 1 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.


Cornify
  • home
  • blog
  • notebooks
  • projects
  • recent
  • about
  • manifesto
  • !

Content Copyright 2006-2010. Links are copyright of respective owners.