Ver Mensaje Individual
  #2 (permalink)  
Antiguo 28/01/2008, 13:11
Avatar de matanga
matanga
 
Fecha de Ingreso: octubre-2007
Ubicación: España
Mensajes: 1.091
Antigüedad: 16 años, 6 meses
Puntos: 85
Re: Update de un campo con condición en otra tabla

Hola,

Puedes utilizar un MERGE.

Código:
SQL> select * from t50;

 IDCLIENTE     IDNAVE     CAMPO3
---------- ---------- ----------
         1          1         10
         2          2         10
         3          3         10
         5          5         10
         6          6         10

SQL> select * from t51;

    IDNAVE     CAMPO5
---------- ----------
         1          1
         2          1
         3          1
         4          1
         5          2

SQL> merge into t50 d
  2   using (select idnave, campo5 from t51 where campo5 = 1) s
  3   on (s.idnave = d.idnave)
  4   when matched then update set campo3 = campo5
  5  /

3 rows merged.

SQL> select * from t50;

 IDCLIENTE     IDNAVE     CAMPO3
---------- ---------- ----------
         1          1          1
         2          2          1
         3          3          1
         5          5         10
         6          6         10
Tambien puedes cambiar esta linea
Código:
when matched then update set campo3 = campo5
por
Código:
when matched then update set campo3 = ALGUN_VALOR
Saludos