I have 4 columns. I want to do the subtraction process in 3 and divide by the fourth.
How do I do this in Oracle DB?
COLUNA1 - COLUNA2 - COLUNA3 = RESULTADO;
RESULTADO / COLUNA4 = COLUNA5
I have 4 columns. I want to do the subtraction process in 3 and divide by the fourth.
How do I do this in Oracle DB?
COLUNA1 - COLUNA2 - COLUNA3 = RESULTADO;
RESULTADO / COLUNA4 = COLUNA5
If you want to return the result directly in the sql query the syntax would be as follows:
select (COLUNA1-COLUNA2-COLUNA3)/COLUNA4 AS Resultado
from SUATABELA
If you need to perform the operation on a PL / SQL block / procedure, the syntax would be
declare
vColuna1 number;
vColuna2 number;
vColuna3 number;
vColuna4 number;
vResultado number;
begin
select COLUNA1, COLUNA2, COLUNA3, COLUNA4 into vColuna1, vColuna2, vColuna3, vColuna4
from SUATABELA
where ID = :CHAVEPK;
vResultado := (vColuna1 - vColuna2 - vColuna3) / vColuna4;
dbms_output.put_line(vResultado);
end;