Script oracle pour vider une base de données utilisé dans Bambo lors d'un processus de datapump
Bonjour,
Je prépare un script oracle automatisé afin de vider une base de données. Ce script sera utilisé par Bambo lors d'un processus de datapump.
Jusqquà présent j'effectuais les requêtes suivantes manuellement dans SQL Developer pour vider la base de données avant d'importer le fichier de datapump.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| select 'drop TABLE ' || object_name || ';' from user_objects where object_type = 'TABLE';
select 'drop view ' || object_name || ';' from user_objects where object_type = 'VIEW';
select 'drop INDEX ' || object_name || ';' from user_objects where object_type = 'INDEX';
select 'drop PACKAGE ' || object_name || ';' from user_objects where object_type = 'PACKAGE';
select 'drop TYPE ' || object_name || ';' from user_objects where object_type = 'TYPE';
select 'drop sequence ' || object_name || ';' from user_objects where object_type = 'SEQUENCE';
select 'drop synonym ' || object_name || ';' from user_objects where object_type = 'SYNONYM';
select 'drop PROCEDURE ' || object_name || ';' from user_objects where object_type = 'PROCEDURE';
select 'drop FUNCTION ' || object_name || ';' from user_objects where object_type = 'FUNCTION';
select 'drop DATABASE LINK ' || object_name || ';' from user_objects where object_type = 'DATABASE LINK';
select 'drop JOB ' || object_name || ';' from user_objects where object_type = 'JOB';
select 'drop MATERIALIZED VIEW ' || object_name || ';' from user_objects where object_type = 'MATERIALIZED VIEW'; |
J'ai besoin maintenant d'éxécuter ces requêtes automatiquement sans faire d'action manuelle. Je dois donc grâce à ce script vider ces objets: TABLE, VIEW, MATERIALIZED VIEW, INDEX, PACKAGE, TYPE, SEQUENCE, SYNONYM, PROCEDURE, FUNCTION, DATABASE LINK et JOB
J'ai commencé à créer ce script:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| BEGIN
FOR cur_rec IN (SELECT object_name, object_type
FROM user_objects
WHERE object_type IN
('TABLE',
'VIEW',
'MATERIALIZED VIEW',
'PACKAGE',
'TYPE',
'PROCEDURE',
'FUNCTION',
'SEQUENCE',
'SYNONYM',
'INDEX',
'DATABASE LINK',
'JOB',
'PACKAGE BODY'
))
LOOP
BEGIN
IF cur_rec.object_type = 'TABLE'
THEN
EXECUTE IMMEDIATE 'DROP '
|| cur_rec.object_type
|| ' "'
|| cur_rec.object_name
|| '" CASCADE CONSTRAINTS';
ELSE
EXECUTE IMMEDIATE 'DROP '
|| cur_rec.object_type
|| ' "'
|| cur_rec.object_name
|| '"';
END IF;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ('FAILED: DROP '
|| cur_rec.object_type
|| ' "'
|| cur_rec.object_name
|| '"'
);
END;
END LOOP;
FOR cur_rec IN (SELECT *
FROM all_synonyms
WHERE table_owner IN (SELECT USER FROM dual))
LOOP
BEGIN
EXECUTE IMMEDIATE 'DROP PUBLIC SYNONYM ' || cur_rec.synonym_name;
END;
END LOOP;
END; |
Mais je ne pense pas qu'il soit optimisé et qu'il résolve les erreurs éventuelles (notamment celles liées aux contraintes)
Pourriez-vous m'aider avec cela ?