Fórum SQL Oracle #485579
15/07/2014
0
Tenho duas tabelas
Tabela1 e Tabela 2
Estas duas tabelas tem um codigo unico como referencia ou seja:
tabela1.codigo = tabela2.codigo
Tenho que fazer um update na tabela1 com os dados da tabela2 validando a coluna codigo.
ou seja:
o update simples seria:
update tabela1 set teste1(valor a ser alterado) = @teste2 (valor na tabela 2 correto)
where tabela1.codigo = tabela2.codigo
Será que deu para entender?
Agradeço a ajuda.
Vinicius Brasil
Curtir tópico
+ 0Posts
15/07/2014
Fabiano Carvalho
UPDATE A SET A.COLUNA1 = 'VALOR' FROM TABELA1 A INNER JOIN TABELA B ON A.CODIGO = B.CODIGO
Gostei + 0
15/07/2014
Vinicius Brasil
UPDATE a SET a.coluna = b.coluna
FROM TABELA1 a
INNER JOIN TABELA2 B
ON A.CODIGO = B.CODIGO
Gostei + 0
16/07/2014
Vinicius Brasil
Obrigado pela ajuda!!!!
update tabela1 t1
set t1.campo = ( select t2.campo_origem
from tabela2 t2
where t1.chave = tabela2.chave
AND ROWNUM = 1
)
where EXISTS ( select 1
from tabela2 t2
where t1.chave = tabela2.chave
);
Pena que vou ficar sem aprender cursor rs..
Gostei + 0
25/07/2014
Marisiana Battistella
Você pode aprender aplicando em outras situações...
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)