Question

Y at-il fonction Oracle qui indiquent l'existence d'un enregistrement, ou toute autre technique utile pour y parvenir?

EDIT: en utilisant l'instruction MERGE je l'ai fait:

MERGE
 INTO  lims_min.mytab src
 USING lims_min.mytab tgt
    ON (    src.col1 = tgt.col1
        AND tgt.col1 = p_val1
        AND src.col2 = tgt.col2
        AND tgt.col2 = p_val2
       )

 WHEN MATCHED
 THEN
 UPDATE
  SET tgt.col3=p_val3,
      tgt.col4=p_val4

 WHEN NOT MATCHED
 THEN
 INSERT  (col1, col2, col3, col4)
 VALUES  (val1, val2, val2, val4);

J'obtiens l'erreur en disant que col3 est l'identifiant non valide. Pas de fautes de frappe, et il est column.p_val1 existant, p_val2, p_val3 et p_val4 sont des paramètres de chaîne qui sont passés à la procédure stockée. Je pense que la question peut se situer dans ces params, peut-être qu'ils devraient être placés à l'intérieur d'une instruction WHERE? Toutes les idées?

Était-ce utile?

La solution

Vous recherchez merge dans Oracle.

MERGE
       INTO  target_table tgt
      USING source_table src
         ON  ( src.object_id = tgt.object_id ) //The key to check if the record exists
       WHEN MATCHED // if exists
       THEN
     UPDATE
        SET   tgt.object_name = src.object_name //update it
        ,     tgt.object_type = src.object_type
       WHEN NOT MATCHED                         // if not exists
       THEN
     INSERT ( tgt.object_id                    //then insert
            , tgt.object_name
            , tgt.object_type )
     VALUES ( src.object_id
            , src.object_name
            , src.object_type );

Autres conseils

Regardez dans l'instruction MERGE

http://psoug.org/reference/merge.html

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top