Standard Utility scriptsThis is a featured page

Platform: Oracle App:
Tool: SQL*Plus
DB Ver: 9.2 App Ver:
Tool Ver: 9.2.0.8
Revision Date: 17-Apr-2006 Keywords: REF, REFERENCE, UTILITY SCRIPTS

Reference Notes

These standard scripts should be placed in the default directory of SQL*Plus.



File Name
Usage
Description
index.sql @index <tablename> Describes the indexes with their columns used on a table
findex.sql @findex <tablename> Describes the functional indexes with their columns used on a table
xp.sql @xp Runs EXPLAIN PLAN on the SQL contained in the file xpt.sql and displays the plan pre formatted


index.sql
-- ------------------------------
-- Check columns used in an index
-- ------------------------------
column column_name format a40
set pagesize 999
SELECT
index_name
,column_name
FROM
all_ind_columns
WHERE 1=1
AND table_name = upper('&&1')
ORDER BY 1,2
;

findex.sql
-- ----------------------------------------
-- Check columns used in a functional index
-- ----------------------------------------
set long 40
set pagesize 999
SELECT
index_name
,column_expression
FROM
all_ind_expressions
WHERE 1=1
AND table_name = upper('&&1')
ORDER BY index_name, column_position
;

xp.sql
-- --------------------------------
-- Execution test for explain plan
-- uses SQL in the xpt.sql script
-- --------------------------------
-- Windows
host copy xphead.sql+xpt.sql+xptail.sql=xpt2.sql
-- Unix
--!cat xphead.sql xpt.sql xptail.sql xpt2.sql
spool xpt.out
@xpt2.sql
spool off

xpt.sql
-- --------------------------------------------
-- SQL to be explained using explain plan tools
-- include terminating semicolon (;)
-- --------------------------------------------
select count(*)
from big_table
;

xphead.sql
-- ----------------------------
-- Explain plan starting script
-- ----------------------------
SET pagesize 999
SET feedback OFF
DELETE FROM plan_table WHERE STATEMENT_ID = 'NOBLEA';
explain plan set statement_id = 'NOBLEA' FOR

xptail.sql
-- ---------------------------------------
-- tail end of the script for explain plan
-- ---------------------------------------
SELECT
ROWNUM||' '||LPAD(' ', 2*(LEVEL-1))||operation||' '||options||' '||
DECODE(object_instance, NULL, object_name
, TO_CHAR(object_instance)||'*'||object_name) PLAN
FROM
plan_table
START WITH id=0
CONNECT BY PRIOR id = parent_id AND statement_id = 'NOBLEA'
ORDER BY id;
ROLLBACK;


consultium
consultium
Latest page update: made by consultium , Oct 9 2009, 11:05 AM EDT (about this update About This Update consultium Edited by consultium

46 words added

view changes

- complete history)
Keyword tags: REF REFERENCE UTILITY SCRIPTS
More Info: links to this page
There are no threads for this page.  Be the first to start a new thread.

Related Content

  (what's this?Related ContentThanks to keyword tags, links to related pages and threads are added to the bottom of your pages. Up to 15 links are shown, determined by matching tags and by how recently the content was updated; keeping the most current at the top. Share your feedback on Wetpaint Central.)