IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

SQL Oracle Discussion :

Select pour une donnée à extraire d'un xml d'une table [11gR2]


Sujet :

SQL Oracle

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Janvier 2009
    Messages
    85
    Détails du profil
    Informations personnelles :
    Âge : 59
    Localisation : Suisse

    Informations forums :
    Inscription : Janvier 2009
    Messages : 85
    Points : 62
    Points
    62
    Par défaut Select pour une donnée à extraire d'un xml d'une table
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    <?xml version="1.0" encoding="UTF-8"?><ConfigurationDTO xmlns="http://xmlns.xxxx.com/LLLL/PS/DDD/DataTransferObjects/ScConfiguration/CAS3/v1" xmlns:disp="DDD" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <General>
        <Id>788</Id>
        <Security>3</Security>
      </General>
    </ConfigurationDTO>
    J'ai une table que je nommerai TEST qui contient un colonne XML. Le contenu de ce champ est représenté par l'extrait ci-contre. Je recherche à extraire le contenu du tag Security avec un select. Comment dois-je faire ?

  2. #2
    Expert éminent sénior Avatar de mnitu
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Octobre 2007
    Messages
    5 611
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Marne (Champagne Ardenne)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2007
    Messages : 5 611
    Points : 11 252
    Points
    11 252
    Par défaut
    Utilisez Xmltable
    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
    18
    19
    20
    21
     
    With Data As (
    Select xmltype('<?xml version="1.0" encoding="UTF-8"?>
    <ConfigurationDTO xmlns="http://xmlns.xxxx.com/LLLL/PS/DDD/DataTransferObjects/ScConfiguration/CAS3/v1" xmlns:disp="DDD" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <General>
        <Id>788</Id>
        <Security>3</Security>
      </General>
    </ConfigurationDTO>') x_el
      from dual
    )
    Select Security
      from Data,
           XmlTable(XMLNAMESPACES(DEFAULT 'http://xmlns.xxxx.com/LLLL/PS/DDD/DataTransferObjects/ScConfiguration/CAS3/v1'
                                 ),
           'for $i in /ConfigurationDTO/General
                     return $i
                    ' 
                    passing x_el
                    Columns Security Number (2) Path 'Security'
                    )

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Janvier 2009
    Messages
    85
    Détails du profil
    Informations personnelles :
    Âge : 59
    Localisation : Suisse

    Informations forums :
    Inscription : Janvier 2009
    Messages : 85
    Points : 62
    Points
    62
    Par défaut
    Merci pour la réponse ! Je suis en train d'adapter votre réponse à mon besoin et lorsque j'exécute la requête ci-dessous j'obtiens aucun résultat. Donc aucune ligne n'est retournée.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    Select security, platform
      from SC_SPEC,
           XmlTable(XMLNAMESPACES(DEFAULT 'http://xmlns.xxxx.com/LLLL/PS/DDD/DataTransferObjects/ScConfiguration/CAS3/v1'
                                 ),
           'for $i in /ConfigurationDTO/General
                     return $i
                    ' 
                    passing CONFIG_XML
                    Columns Security Number (2) Path 'Security',
                            Platform VARCHAR2(20) Path 'Platform'
                    );
    J'ai le sentiment de passer à côté de quelque chose ! Et si je veux extraire un autre élément d'un autre tag, disons, SERVICE, je vais devoir faire une autre boucle sur /ConfigurationDTO/SERVICE ?

  4. #4
    Expert éminent sénior Avatar de mnitu
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Octobre 2007
    Messages
    5 611
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Marne (Champagne Ardenne)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2007
    Messages : 5 611
    Points : 11 252
    Points
    11 252
    Par défaut
    Il faut le contenu de la zone XML sinon on peut rien dire. Postez un exemple plus proche de vos besoins.

  5. #5
    Membre du Club
    Profil pro
    Inscrit en
    Janvier 2009
    Messages
    85
    Détails du profil
    Informations personnelles :
    Âge : 59
    Localisation : Suisse

    Informations forums :
    Inscription : Janvier 2009
    Messages : 85
    Points : 62
    Points
    62
    Par défaut
    D'accord ! Voici le XML :

    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
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    <?xml version="1.0" encoding="UTF-8"?><ScConfigurationDTO xmlns="http://xmlns.PROVIGO.com/PROVIGO/PS/CSI/DataTransferObjects/ScConfiguration/CUISINE/v4" xmlns:disp="CSI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <General>
        <Id>790</Id>
        <Security>1</Segment>
        <CommercialOperatorName>PROVIGO</CommercialOperatorName>
        <BCountry>CHX HE-SIT</BCountry>
        <SolutionExpert>PAUL</SolutionExpert>
        <ProgramManager>DURUISSEAU</ProgramManager>
        <SecurityOfficer/>
        <PlatformArchitect>ROBINETTRIE</PlatformArchitect>
        <CasSegmentationOwner/>
        <Platform>CUISINE</Platform>
        <Technology>LAVABO</Technology>
        <ScProfileType>Custom</ScProfileType>
        <ScLabel>TEST</ScLabel>
        <ScDescription>TEST PHASE2</ScDescription>
        <ApduInterface>CUISINE</ApduInterface>
        <ScArticle>76</ScArticle>
        <Revision>173</Revision>
        <RevisionName>420-S64</RevisionName>
        <IemmCasId>1875</IemmCasId>
        <EmmCasId>1875</EmmCasId>
        <EcmCasId>1875</EcmCasId>
        <EcmCasIdNoCert>1875</EcmCasIdNoCert>
        <ScActivation>false</ScActivation>
        <ScGroupSize>512</ScGroupSize>
        <ScSetID>0104</ScSetID>
        <ScSetIDNoCert>0104</ScSetIDNoCert>
        <IsSegmented>false</IsSegmented>
        <SegmentValue>00</SegmentValue>
        <CcoStatus>true</CcoStatus>
      </General>
      <Pop>
        <Ppid>0211</Ppid>
        <Timezone>0</Timezone>
        <Dlst>false</Dlst>
        <RDateTime>PAST</RDateTime>
        <RDateDeltaMax>120</RDateDeltaMax>
        <Opn>534F50</Opn>
      </Pop>
    </ScConfigurationDTO>
    Alors j'aimerais sortir du XML les données des tag Technology, IemmCasId, EmmCasId, EcmCasId et Ppid. Et que ce passe-t-il si j'ai des XML qui ont ceci en entête :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    xmlns="http://xmlns.PROVIGO.com/PROVIGO/PS/CSI/DataTransferObjects/ScConfiguration/CUISINE/v3" xmlns:disp="CSI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    et
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    xmlns="http://xmlns.PROVIGO.com/PROVIGO/PS/CSI/DataTransferObjects/ScConfiguration/CUISINE/v2" xmlns:disp="CSI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    ou même
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    xmlns="http://xmlns.PROVIGO.com/PROVIGO/PS/CSI/DataTransferObjects/ScConfiguration/SALON/v4" xmlns:disp="CSI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    Merci.

  6. #6
    Expert éminent sénior Avatar de mnitu
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Octobre 2007
    Messages
    5 611
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Marne (Champagne Ardenne)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2007
    Messages : 5 611
    Points : 11 252
    Points
    11 252
    Par défaut
    Si le espace de nommage par défaut change il faut prendre cela en compte dans la définition du XMLTable.
    Voilà votre exemple:
    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
    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
     
    With Data As (
    Select XmlType('<?xml version="1.0" encoding="UTF-8"?>
    <ScConfigurationDTO xmlns="http://xmlns.PROVIGO.com/PROVIGO/PS/CSI/DataTransferObjects/ScConfiguration/CUISINE/v4" xmlns:disp="CSI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <General>
        <Id>790</Id>
        <Security>1</Security>
        <CommercialOperatorName>PROVIGO</CommercialOperatorName>
        <BCountry>CHX HE-SIT</BCountry>
        <SolutionExpert>PAUL</SolutionExpert>
        <ProgramManager>DURUISSEAU</ProgramManager>
        <SecurityOfficer/>
        <PlatformArchitect>ROBINETTRIE</PlatformArchitect>
        <CasSegmentationOwner/>
        <Platform>CUISINE</Platform>
        <Technology>LAVABO</Technology>
        <ScProfileType>Custom</ScProfileType>
        <ScLabel>TEST</ScLabel>
        <ScDescription>TEST PHASE2</ScDescription>
        <ApduInterface>CUISINE</ApduInterface>
        <ScArticle>76</ScArticle>
        <Revision>173</Revision>
        <RevisionName>420-S64</RevisionName>
        <IemmCasId>1875</IemmCasId>
        <EmmCasId>1875</EmmCasId>
        <EcmCasId>1875</EcmCasId>
        <EcmCasIdNoCert>1875</EcmCasIdNoCert>
        <ScActivation>false</ScActivation>
        <ScGroupSize>512</ScGroupSize>
        <ScSetID>0104</ScSetID>
        <ScSetIDNoCert>0104</ScSetIDNoCert>
        <IsSegmented>false</IsSegmented>
        <SegmentValue>00</SegmentValue>
        <CcoStatus>true</CcoStatus>
      </General>
      <Pop>
        <Ppid>0211</Ppid>
        <Timezone>0</Timezone>
        <Dlst>false</Dlst>
        <RDateTime>PAST</RDateTime>
        <RDateDeltaMax>120</RDateDeltaMax>
        <Opn>534F50</Opn>
      </Pop>
    </ScConfigurationDTO>
    ') x_el
    from dual
    )
    Select Security,
           Technology, 
           IemmCasId, 
           EmmCasId, 
           EcmCasId,
           Ppid
      from Data,
           XmlTable(XMLNAMESPACES(DEFAULT 'http://xmlns.PROVIGO.com/PROVIGO/PS/CSI/DataTransferObjects/ScConfiguration/CUISINE/v4'
                                  ),
           'for $i in /ScConfigurationDTO
                     return $i
                    ' 
                    passing x_el
                    Columns Security      Number (2)     Path 'General/Security',
                            Technology    Varchar2(20)   Path 'General/Technology',
                            IemmCasId     Number(6)      Path 'General/IemmCasId',
                            EmmCasId      Number(6)      Path 'General/EmmCasId',
                            EcmCasId      Number(6)      Path 'General/EcmCasId',
                            Ppid          Number(6)      Path 'Pop/Ppid'
     
                    )

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 3
    Dernier message: 13/06/2012, 10h14
  2. Réponses: 0
    Dernier message: 07/07/2008, 20h42
  3. Afficher un fragment HTML d'une donnée d'un fichier XML ?
    Par tarekos dans le forum XML/XSL et SOAP
    Réponses: 21
    Dernier message: 12/06/2008, 10h18
  4. [XML] Modification d'une donnée d'un fichier XML
    Par mardachris dans le forum XML/XSL et SOAP
    Réponses: 3
    Dernier message: 15/12/2006, 19h46
  5. Réponses: 3
    Dernier message: 13/12/2004, 13h54

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo