Précédent   Forum des professionnels en informatique > Bases de données > Oracle > SQL
SQL Forum d'entraide sur le SQL pour Oracle
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 25/01/2011, 12h34   #1
Membre éprouvé
 
Avatar de dumas.blr
 
Homme Jean-Yves DUMAS
Consultant informatique
Inscription : juin 2010
Messages : 325
Détails du profil
Informations personnelles :
Nom : Homme Jean-Yves DUMAS
Âge : 48
Localisation : France, Hauts de Seine (Île de France)

Informations professionnelles :
Activité : Consultant informatique
Secteur : Conseil

Informations forums :
Inscription : juin 2010
Messages : 325
Points : 447
Points : 447
Par défaut Parsing de chaine de longueur variable, est-ce que l'utilisation de REGEXP est adaptée ?

Bonjour,

Je dois faire une cartographie d'un univers BO.
A cet effet, j'ai pu récupérer l'ensemble des objets de celui-ci à partir du référentiel ORACLE.
Je souhaite maintenant énumérer la liste des tables et des colonnes associées. A cet effet, Je possède 2 colonnes contenant les clause SELECT et les clause WHERE. Chaque colonne peut bien sur contenir 1 ou plusieurs tables/colonne :

ex1 (le + simple) :
Code :
TP1_BB_CORRESP_CONTRAT.EXPGDF
Ex2 (plus compliqué):
Code :
sum(TP1_BB_ECART_BILAN_ZT_M.ECRETEMENT_P1_M)
Ex3 (encore plus compliqué):
Code :
1
2
3
4
5
6
7
8
CASE
          WHEN (S_BO_ECART_BILAN_A_JOUR.ID_ZONE_TARIF = 'ZT000B')
             THEN 'Zone Nord B'
          WHEN (S_BO_ECART_BILAN_A_JOUR.ID_ZONE_TARIF = 'ZT000N')
             THEN 'Zone Nord'
          WHEN (S_BO_ECART_BILAN_A_JOUR.ID_ZONE_TARIF = 'ZT000S')
             THEN 'Zone Sud'
       END
Ex 4 (aussi compliqué) :
Code :
sum(decode(TP1_BB_POINT_CONTRAT.DIRECTION_FLUX,S_BO_PROGRAMMATION_A_JOUR.SENS_NOMINATION,S_BO_PROGRAMMATION_A_JOUR.Q_PROGRAMMEE_M,(S_BO_PROGRAMMATION_A_JOUR.Q_PROGRAMMEE_M*(-1))))
Comme je dois reporter les définition de mes objet dans un dictionnaire central BO, il m'est impossible d'utiliser des fonctions PL/SQL; je dois donc tout faire en SQL natif.

J'ai commencé à utiliser les fonctions INSTR, TRANSLATE et SUBSTR, mais ma requête commence à ressembler à une véritable usine à gaz, car je dois coder en fonction du nombre de colonnes que je trouve (en l'occurence le nombre de point ('.') dans mon champ.
Et ça ne marche pas encore ...

voici un premier jet de ma requête :
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
SELECT c.ch,
       (LENGTH(c.ch) - LENGTH(REPLACE(c.ch, '.', NULL))) AS nb_occ,
       c.pos_point,
       instr(c.ch, '|', -pos_point, 1) pos_table,
       decode(0,
              instr(c.ch, '|', pos_point, 1),
              length(c.ch) - pos_point,
              instr(c.ch, '|', pos_point, 1) - pos_point - 1) AS lg_champ,
       decode(0,
              instr(c.ch, '|', -pos_point, 1),
              pos_point - 1,
              pos_point - instr(c.ch, '|', -pos_point, 1) - 1) AS lg_table
  FROM (SELECT B.ch_a_analyser AS ch,
               instr(b.ch_a_analyser, '.', 1, 1) AS pos_point
          FROM (SELECT a.obj_name,
                       a.obj_select,
                       LENGTH(obj_select) AS lg,
                       translate(obj_select, '(),+-=>< ', '|||||||||') AS ch_a_analyser,
                       (LENGTH(obj_select) -
                       LENGTH(REPLACE(obj_select, '.', NULL))) AS nb_occ
                  FROM (SELECT UNV_CLASS.CLS_NAME,
                               UNV_OBJECT.OBJ_NAME,
                               object_tables.TAB_NAME,
                               object_select1.OBJ_DATAVALUE ||
                               object_select2.OBJ_DATAVALUE AS obj_select,
                               object_where1.OBJ_DATAVALUE ||
                               object_where2.OBJ_DATAVALUE AS obj_where
                          FROM UNV_CLASS,
                               UNV_OBJECT,
                               UNV_TABLE object_tables,
                               UNV_OBJECT_DATA object_select1,
                               UNV_OBJECT_DATA object_select2,
                               UNV_OBJECT_DATA object_where1,
                               UNV_OBJECT_DATA object_where2,
                               UNV_UNIVERSE,
                               UNV_OBJ_TAB
                         WHERE (UNV_CLASS.UNIVERSE_ID(+) =
                               UNV_UNIVERSE.UNIVERSE_ID)
                           AND (UNV_OBJECT.UNIVERSE_ID = UNV_CLASS.UNIVERSE_ID)
                           AND (UNV_OBJECT.CLASS_ID = UNV_CLASS.CLASS_ID)
                           AND (object_select1.OBJECT_ID(+) =
                               UNV_OBJECT.OBJECT_ID)
                           AND (object_select1.UNIVERSE_ID(+) =
                               UNV_OBJECT.UNIVERSE_ID)
                           AND (object_select2.UNIVERSE_ID(+) =
                               object_select1.UNIVERSE_ID)
                           AND (object_select2.OBJECT_ID(+) =
                               object_select1.OBJECT_ID)
                           AND (object_where1.UNIVERSE_ID(+) =
                               UNV_OBJECT.UNIVERSE_ID)
                           AND (object_where1.OBJECT_ID(+) =
                               UNV_OBJECT.OBJECT_ID)
                           AND (object_where2.UNIVERSE_ID(+) =
                               object_where1.UNIVERSE_ID)
                           AND (object_where2.OBJECT_ID(+) =
                               object_where1.OBJECT_ID)
                           AND (object_where1.OBJ_DATATYPE(+) = 'W')
                           AND (object_select1.OBJ_DATATYPE(+) = 'S')
                           AND (object_select2.OBJ_DATATYPE(+) = 'S')
                           AND (object_where2.OBJ_DATATYPE(+) = 'W')
                           AND (object_select1.OBJ_SLICE(+) = 1)
                           AND (object_where1.OBJ_SLICE(+) = 1)
                           AND (object_select2.OBJ_SLICE(+) = 2)
                           AND (object_where2.OBJ_SLICE(+) = 2)
                           AND (UNV_OBJ_TAB.UNIVERSE_ID(+) =
                               UNV_OBJECT.UNIVERSE_ID)
                           AND (UNV_OBJ_TAB.OBJECT_ID(+) =
                               UNV_OBJECT.OBJECT_ID)
                           AND (object_tables.UNIVERSE_ID(+) =
                               UNV_OBJ_TAB.UNIVERSE_ID)
                           AND (object_tables.TABLE_ID(+) =
                               UNV_OBJ_TAB.TABLE_ID)
                           AND (UNV_UNIVERSE.UNI_LONGNAME = 'BOBILAN')) a) b) C
Vous voyez déjà la complexité ... et encore, je ne traite que le cas ou je ne traite que le premier point, et dans ce cas ça ne marche pas si j'ai plusieurs points ...

Ne connaissant pas du tout l'utilisation des fonctions REGEXP, je voulais savoir si celles-ci sont adaptées à ma problématique, avant de me plonger dans une étude approfondie de celle-ci.

Merci d'avance pour vos réponses éclairées.
dumas.blr est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 02h57.


 
 
 
 
Partenaires

Hébergement Web