Skip to content

Instantly share code, notes, and snippets.

@thiago-vieira
Created August 24, 2020 20:45
Show Gist options
  • Save thiago-vieira/06e2927852894bdd40e9f06d146a54bf to your computer and use it in GitHub Desktop.
Save thiago-vieira/06e2927852894bdd40e9f06d146a54bf to your computer and use it in GitHub Desktop.
List Oracle sequences not in use
-- first, update dbname string
SELECT sequence_name FROM ALL_SEQUENCES WHERE SEQUENCE_OWNER =
'dbname' and sequence_name like 'ISEQ$$_%' AND sequence_name not in (
with xml as ( select dbms_xmlgen.getxmltype( 'select
column_name, data_default from all_tab_columns where owner=''dbname''
AND DATA_DEFAULT IS NOT NULL ') x from dual),
col_defs as ( select extractValue(xt.object_value,
'/ROW/COLUMN_NAME') as col_name, extractValue(xt.object_value,
'/ROW/DATA_DEFAULT') as d_def from xml,
table(xmlsequence(extract(xml.x, '/ROWSET/ROW'))) xt
)
select REPLACE(REPLACE(to_char(d_def), '"dbname"."' , ''),
'".nextval', '') from col_defs
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment