Bonjour à tous,
je ne sais pas comment faire pour écrire le script suivant en utilisant une boucle de traitement plutôt que de répéter les requêtes SQL.
J'ai pensé à quelque chose du style mais je ne sais pas comment spécifier le nom du schéma dans la boucle, sachant que "schema_20xx" correspond au nom du schéma annuel.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 insert into schema_2013.maTable_1 (champ_1,champ_2) select distinct 2013, monChamp from schema_2013.maTable_2 where condition; insert into schema_2013.maTable_1 (champ_1,champ_2) select distinct 2012, monChamp from schema_2012.maTable_2 where condition; insert into schema_2013.maTable_1 (champ_1,champ_2) select distinct 2011, monChamp from schema_2011.maTable_2 where condition; insert into schema_2013.maTable_1 (champ_1,champ_2) select distinct 2010, monChamp from schema_2010.maTable_2 where condition; insert into schema_2013.maTable_1 (champ_1,champ_2) select distinct 2009, monChamp from schema_2009.maTable_2 where condition; ...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 BEGIN FOR i IN 1..5 LOOP INSERT INTO schema_2013.maTable_1 (champ_1,champ_2) SELECT DISTINCT 20xx, monChamp FROM schema_20xx.maTable_2 WHERE condition; END LOOP; END; /
Enfin, quelles seraient les adaptations à écrire pour utiliser le code de la boucle dans du SQLPLUS plutôt que dans SQL Developer ? L'idée étant d'appeler la requête via un fichier .bat qui ouvre SQL PLUS...
Merci à tous,
MarieO
Partager