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

PL/SQL Oracle Discussion :

Importer les données d'une table dans une autre


Sujet :

PL/SQL Oracle

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Inscrit en
    Août 2009
    Messages
    273
    Détails du profil
    Informations forums :
    Inscription : Août 2009
    Messages : 273
    Par défaut Importer les données d'une table dans une autre
    Bonjour,

    J'essaie d'importer les données d'une table dans une autre en exécutant ce code mais ça ne marche pas mais lorsque j'inverse l'update avec l'insert ça marche mais lorsque j'exécute la procédure une deuxième fois les enregistrements se font en double.

    Je sais qu'il y a le select count into mais je ne sais pas comment faire ? ou bien une autre solution si quelqu'un peut m'aider ?

    Merci d'avance !

    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
    create or replace PROCEDURE IMPORT_TRANSFERT
    IS
      CURSOR CUR
      IS
        SELECT
          UPP_NAM,UPP_FNA,UPP_LOG,UPP_PWD,UPP_STA,UPP_INM,UPP_END,UPP_MEL,UPP_IPA,UPP_SST,UPP_PSS,TIT_KEY,CIV_KEY,AUD_KEY,UPP_PPW,
          UPP_DPW,UPP_TIC,UPP_SUD,UPP_INN,CPS_KEY,MAU_KEY,UPP_WWI,UPP_EXT,UPP_UPD,UPP_SGN,UPP_DAD,UPP_DAF,UPP_AMS
        FROM PPP_UPP;
    BEGIN
      FOR CUR_REC IN CUR
      LOOP
        BEGIN
          UPDATE PPP_MAIN_TRANSFERT
          SET PER_NAM = CUR_REC.UPP_NAM, PER_FNA = CUR_REC.UPP_FNA, UPP_LOG = CUR_REC.UPP_LOG, UPP_PWD = CUR_REC.UPP_PWD,
              UPP_STA = CUR_REC.UPP_STA, UPP_INM = CUR_REC.UPP_INM, UPP_END = CUR_REC.UPP_END, UPP_MEL = CUR_REC.UPP_MEL,
              UPP_IPA = CUR_REC.UPP_IPA, UPP_SST = CUR_REC.UPP_SST, UPP_PSS = CUR_REC.UPP_PSS, TIT_KEY = CUR_REC.TIT_KEY,
              CIV_KEY = CUR_REC.CIV_KEY, AUD_KEY = CUR_REC.AUD_KEY, UPP_PPW = CUR_REC.UPP_PPW, UPP_DPW = CUR_REC.UPP_DPW,
              UPP_TIC = CUR_REC.UPP_TIC, UPP_SUD = CUR_REC.UPP_SUD, UPP_INN = CUR_REC.UPP_INN, CPS_KEY = CUR_REC.CPS_KEY,
              MAU_KEY = CUR_REC.MAU_KEY, UPP_WWI = CUR_REC.UPP_WWI, UPP_EXT = CUR_REC.UPP_EXT, UPP_UPD = CUR_REC.UPP_UPD, 
              UPP_SGN = CUR_REC.UPP_SGN, UPP_DAD = CUR_REC.UPP_DAD, UPP_DAF = CUR_REC.UPP_DAF
          WHERE PER_NAM = CUR_REC.UPP_NAM
            AND PER_FNA  = CUR_REC.UPP_FNA
            AND UPP_LOG  = CUR_REC.UPP_LOG;
        EXCEPTION
          -- SI L'INSERTION ECHOUE, ON FAIT UN UPDATE
          WHEN NO_DATA_FOUND THEN
            BEGIN
              INSERT INTO PPP_MAIN_TRANSFERT
              (
                PER_NAM,PER_FNA,UPP_LOG,UPP_PWD,UPP_STA,UPP_INM,UPP_END,UPP_MEL,UPP_IPA,UPP_SST,UPP_PSS,TIT_KEY,CIV_KEY,AUD_KEY,
                UPP_PPW,UPP_DPW,UPP_TIC,UPP_SUD,UPP_INN,CPS_KEY,MAU_KEY,UPP_WWI,UPP_EXT,UPP_UPD,UPP_SGN,UPP_DAD,UPP_DAF,UPP_AMS
              )
              VALUES 
              (
                CUR_REC.UPP_NAM,CUR_REC.UPP_FNA,CUR_REC.UPP_LOG,CUR_REC.UPP_PWD,CUR_REC.UPP_STA,CUR_REC.UPP_INM,CUR_REC.UPP_END,
                CUR_REC.UPP_MEL,CUR_REC.UPP_IPA,CUR_REC.UPP_SST,CUR_REC.UPP_PSS,CUR_REC.TIT_KEY,CUR_REC.CIV_KEY,CUR_REC.AUD_KEY,
                CUR_REC.UPP_PPW,CUR_REC.UPP_DPW,CUR_REC.UPP_TIC,CUR_REC.UPP_SUD,CUR_REC.UPP_INN,CUR_REC.CPS_KEY,CUR_REC.MAU_KEY,
                CUR_REC.UPP_WWI,CUR_REC.UPP_EXT,CUR_REC.UPP_UPD,CUR_REC.UPP_SGN,CUR_REC.UPP_DAD,CUR_REC.UPP_DAF,CUR_REC.UPP_AMS
              );
            END;
     
        END;
        COMMIT;
      END LOOP; -- END EXCEPTION
    END; -- END PROGRAM

  2. #2
    Expert éminent
    Avatar de orafrance
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    15 967
    Détails du profil
    Informations personnelles :
    Âge : 48
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 15 967
    Par défaut
    Utilise Merge qui évite d'utiliser du PL/SQL

  3. #3
    Membre éclairé
    Inscrit en
    Août 2009
    Messages
    273
    Détails du profil
    Informations forums :
    Inscription : Août 2009
    Messages : 273
    Par défaut
    Je ne sais pas comment faire sinon j'aurai préféré faire de cette façon ?

  4. #4
    Expert éminent
    Avatar de orafrance
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    15 967
    Détails du profil
    Informations personnelles :
    Âge : 48
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 15 967
    Par défaut
    tu fais une recherche sur le forum et/ou tu lis la doc

  5. #5
    Membre éclairé
    Inscrit en
    Août 2009
    Messages
    273
    Détails du profil
    Informations forums :
    Inscription : Août 2009
    Messages : 273
    Par défaut
    Sinon est ce que mon update est correcte ?
    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
     
     
    DECLARE
     
      CURSOR CUR
      IS
        SELECT
          PER_NAM,PER_FNA,UPP_LOG,UPP_PWD,UPP_STA,UPP_INM,UPP_END,UPP_MEL,UPP_IPA,UPP_SST,UPP_PSS,TIT_KEY,CIV_KEY,AUD_KEY,UPP_PPW,
          UPP_DPW,UPP_TIC,UPP_SUD,UPP_INN,CPS_KEY,MAU_KEY,UPP_WWI,UPP_EXT,UPP_UPD,UPP_SGN,UPP_DAD,UPP_DAF,UPP_AMS
        FROM PPP_MAIN_TRANSFERT;
     
    BEGIN
     
      FOR CUR_REC IN CUR LOOP
          UPDATE PPP_UPP
          SET UPP_NAM = CUR_REC.PER_NAM, UPP_FNA = CUR_REC.PER_FNA, UPP_LOG = CUR_REC.UPP_LOG, UPP_PWD = CUR_REC.UPP_PWD,
              UPP_STA = CUR_REC.UPP_STA, UPP_INM = CUR_REC.UPP_INM, UPP_END = CUR_REC.UPP_END, UPP_MEL = CUR_REC.UPP_MEL,
              UPP_IPA = CUR_REC.UPP_IPA, UPP_SST = CUR_REC.UPP_SST, UPP_PSS = CUR_REC.UPP_PSS, TIT_KEY = CUR_REC.TIT_KEY,
              CIV_KEY = CUR_REC.CIV_KEY, AUD_KEY = CUR_REC.AUD_KEY, UPP_PPW = CUR_REC.UPP_PPW, UPP_DPW = CUR_REC.UPP_DPW,
              UPP_TIC = CUR_REC.UPP_TIC, UPP_SUD = CUR_REC.UPP_SUD, UPP_INN = CUR_REC.UPP_INN, CPS_KEY = CUR_REC.CPS_KEY,
              MAU_KEY = CUR_REC.MAU_KEY, UPP_WWI = CUR_REC.UPP_WWI, UPP_EXT = CUR_REC.UPP_EXT, UPP_UPD = CUR_REC.UPP_UPD, 
              UPP_SGN = CUR_REC.UPP_SGN, UPP_DAD = CUR_REC.UPP_DAD, UPP_DAF = CUR_REC.UPP_DAF
          WHERE UPP_NAM = CUR_REC.PER_NAM
            AND UPP_FNA  = CUR_REC.PER_FNA
            AND UPP_LOG  = CUR_REC.UPP_LOG;
      END LOOP;
     
      COMMIT;
    END;

  6. #6
    Modérateur
    Avatar de Waldar
    Homme Profil pro
    Sr. Specialist Solutions Architect @Databricks
    Inscrit en
    Septembre 2008
    Messages
    8 454
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Sr. Specialist Solutions Architect @Databricks
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2008
    Messages : 8 454
    Par défaut
    Oui, il a l'air correct.

Discussions similaires

  1. copier une table d'une BDD dans une table d'une autre BDD
    Par faniette dans le forum C++Builder
    Réponses: 2
    Dernier message: 15/05/2013, 10h17
  2. Réponses: 7
    Dernier message: 25/03/2011, 10h52
  3. [AC-2003] insert des données d'une table dans une table d'une base externe
    Par marieo dans le forum VBA Access
    Réponses: 1
    Dernier message: 30/11/2009, 14h29
  4. importer les noms de fichiers html dans une table access
    Par abane badis dans le forum Access
    Réponses: 3
    Dernier message: 14/11/2005, 17h25

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