Created
August 24, 2020 20:45
-
-
Save thiago-vieira/06e2927852894bdd40e9f06d146a54bf to your computer and use it in GitHub Desktop.
List Oracle sequences not in use
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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