3
Good afternoon ,
How do I update with Inner Join , because I need to change the field idnaoleitura = 24 to idnaoleitura = 0 where idrota in (35,45,48,53,60,68,70,79) , remembering the idrota this in another table.
The table calculo_leituras_ucb has the field idnaoleitura The calculo_data table has the idrota field The keys are the fields : IDUC
calculo_leituras_ucb.iduc calculo_data.iduc
Follows below code.
begin
execute immediate 'alter table calculo_leituras_ucb disable all triggers';
execute immediate 'alter table calculo_dados disable all triggers';
UPDATE calculo_leituras_ucb
SET calculo_leituras_ucb.idnaoleitura = 0
from calculo_leituras_ucb
inner join calculo_dados on calculo_leituras_ucb.iduc = calculo_dados.iduc
where calculo_leituras_ucb.ano_mes = ('01/07/2014')
and calculo_dados.idrota in (35,45,48,53,60,68,70,79)
and calculo_leituras_ucb.idnaoleitura = 24 ;
commit;
execute immediate 'alter table calculo_leituras_ucb enable all triggers';
execute immediate 'alter table calculo_dados enable all triggers';
exception when others then
rollback;
execute immediate 'alter table Calculo_leituras_ucb enable all triggers';
execute immediate 'alter table calculo_dados enable all triggers';
RAISE_APPLICATION_ERROR(-20000,'tem erro no script >:( !!!.'|| sqlerrm(sqlcode));
end;