An Oracle SQLPlus / SQLCL script that generates sql statements then executes them

Here is a easy example of a sql script that generates sql statements and then executes them.
Hope it helps.  Mike

SET PAGESIZE 0
SET TERMOUT OFF
SET TRIMSPOOL ON
SPOOL executeStatements.sql
SELECT 'SELECT count(*) from dba_tables where owner='''||trim(username)||''';'
from dba_users WHERE ROWNUM < 15;
SELECT 'SELECT count(*) from dba_indexes where owner='''||trim(username)||''';'
from dba_users WHERE ROWNUM < 5;
spool off
set heading on;
set verify on;
set echo on;
set termout on;
@executeStatements.sql
exit

 

Leave a Comment

Scroll to Top