Tenho uma base de dados em oracle onde necessito excluir todos os objetos de um determinado Schema, não posso excluir o Schema, pois a validação do sistema é feita com base em um algoritmo que leva em consideração o ID do Schema.
1 Resposta
Segue abaixo script para apagar todos os objetos de um owner, ter controle do que está excluindo e gerar um log de cada objeto a ser excluído.
set verify off
set heading off
set feedback off
accept vo prompt 'Informe o Owner: '
accept dir prompt 'Diretorio de spool: '
column global_name new_value instancia noprint
select replace(global_name, '.WORLD', '') global_name from global_name;
spool "&dir\&Vo._&instancia._drop_obj_schema.sql"
prompt spool "&dir\&Vo._&instancia._drop_obj_schema.log"
prompt
prompt set echo on
prompt
select 'ALTER TABLE '||OWNER||'."'||TABLE_NAME||'" DROP CONSTRAINT "'||CONSTRAINT_NAME||'";'
from dba_constraints
where owner = upper('&Vo')
and constraint_type = 'R'
/
select DISTINCT 'DROP SEQUENCE '||SEQUENCE_OWNER||'."'||SEQUENCE_NAME||'";'
from dba_sequences
where sequence_owner = upper('&Vo')
/
select DISTINCT 'DROP '||TYPE||' '||OWNER||'."'||NAME||'";'
from dba_source
where owner = upper('&Vo')
/
select 'DROP VIEW '||OWNER||'."'|| VIEW_NAME||'";'
from dba_views
where owner = upper('&Vo')
/
select 'DROP TABLE '||OWNER||'."'||TABLE_NAME||'" PURGE;'
from dba_tables
where owner = upper('&Vo')
/
select 'DROP SYNONYM '||OWNER||'."'||SYNONYM_NAME||'";'
from dba_synonyms
where owner = upper('&Vo')
/
select 'DROP TYPE '||OWNER||'."'||TYPE_NAME||'";'
from dba_types
where owner = upper('&Vo')
/
select 'DROP MATERIALIZED VIEW '||OWNER||'."'||MVIEW_NAME||'";'
from dba_mviews
where owner = upper('&Vo')
/
SELECT 'PURGE TABLE ' || OWNER || '."' || ORIGINAL_NAME || '";'
FROM dba_recyclebin
WHERE owner = upper('&Vo')
and type = 'TABLE'
/
prompt
prompt set echo off
prompt
prompt
prompt spool off
spool off
spool "&dir\&Vo._&instancia._drop_syn.sql"
prompt spool "&dir\&Vo._&instancia._drop_syn.log"
prompt
prompt set echo on
prompt
select 'drop public synonym ' || synonym_name || ';'
from dba_synonyms
where table_owner = upper('&Vo')
and owner = 'PUBLIC'
and db_link is null
order by synonym_name
/
prompt
prompt
prompt
select 'drop synonym ' || owner || '.' || synonym_name || ';'
from dba_synonyms
where table_owner = upper('&Vo')
and owner != 'PUBLIC'
and db_link is null
order by owner, synonym_name
/
prompt
prompt
prompt set echo off
prompt
prompt
prompt spool off
spool off
undef vo
undef dir
undef instancia
set verify on
set heading on
set feedback on
Fonte: http://www.dirceuresende.com/blog/apagando-todos-os-objetos-de-um-owner-no-oracle-database/
-
valeu, vou testar e depois sinalizo como resposta. Commented 8/03/2016 às 13:26
-
sabe me dizer se o oracle 11g tem a opção
transform=disable_archive_logging:Y
? Commented 8/03/2016 às 13:27 -
Esse seria um novo parâmetro para DataPump do 12c, conforme artigo no dba-oracle– DavidCommented 8/03/2016 às 13:34
-
1
-
1