Extremely doubtful IF

Este forum é dedicado a códigos errados que se encontram por aí, ou seja, coisas que não se deve fazer de jeito nenhum! Não coloque neste forum dúvidas! (apenas situações bizarras do nosso dia a dia :-)
Post Reply
Diego_Mello
Rank: DBA Júnior
Rank: DBA Júnior
Posts: 229
Joined: Fri, 05 Sep 2008 2:59 pm
Location: Igrejinha - RS
Diego Mello
Igrejinha - RS
www.twitter.com/diegolmello

I found this this morning ...

Select all

 
function CF_TOTAL_PARESFormula return Number is 
  vtotal_pares  number(8); 
begin 
  if :pares_linha > 0 then 
    vtotal_pares := :pares_linha; 
  else 
    vtotal_pares := 0; 
  end if;   
  if vtotal_pares = 0 then 
    return(0); 
  else 
    return(vtotal_pares); 
  end if;   
end;       
DanielNN
Moderador
Moderador
Posts: 641
Joined: Mon, 03 Sep 2007 3:26 pm
Location: Fortaleza - CE
att,

Daniel N.N.

Apparently, the person who was testing wanted it to be assigned the value 0.
What is cooler is not having another if but the other is completely dispensable.
to make a simple return (v_total_par).
If you can see if it is 0 variable, return 0:

Select all

  if vtotal_pares = 0 then 
    return(0); 
  else 
    return(vtotal_pares); 
  end if;  
Diego_Mello
Rank: DBA Júnior
Rank: DBA Júnior
Posts: 229
Joined: Fri, 05 Sep 2008 2:59 pm
Location: Igrejinha - RS
Diego Mello
Igrejinha - RS
www.twitter.com/diegolmello

It is neither the question of avoiding negative pairs.
Thinking a little more on business rule, it is impossible to have negative pairs.
Soon, the solution would be very, but much simpler.

Select all

 RETURN NVL(:pares_linha, 0);
and if you want to simplify even more, simply put the NVL straight into Query: P
User avatar
dr_gori
Moderador
Moderador
Posts: 5024
Joined: Mon, 03 May 2004 3:08 pm
Location: Portland, OR USA
Contact:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

From what I understood, if the number is negative, you have to go to zero.

Then something like this:

Select all

IF :pares_linha <= 0  --Se for menor que zero, retorna zero. 
THEN return 0; 
ELSE return :pares_linha;   --Senão, retorna o próprio numero. 
END IF;
or, can do in a line only:

Select all

RETURN  DECODE ( SIGN(:pares_linha), -1, 0, :pares_linha)
User avatar
dr_gori
Moderador
Moderador
Posts: 5024
Joined: Mon, 03 May 2004 3:08 pm
Location: Portland, OR USA
Contact:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

It is impossible to have negative pairs.
is right :-D
DanielNN
Moderador
Moderador
Posts: 641
Joined: Mon, 03 Sep 2007 3:26 pm
Location: Fortaleza - CE
att,

Daniel N.N.

Truth. Of course there should be no negative. But coming from this IF there, does anyone still doubt any negative pairs ???
Hehehehehhe.
Diego_Mello
Rank: DBA Júnior
Rank: DBA Júnior
Posts: 229
Joined: Fri, 05 Sep 2008 2:59 pm
Location: Igrejinha - RS
Diego Mello
Igrejinha - RS
www.twitter.com/diegolmello

Auheuaheuahe: P
User avatar
dr_gori
Moderador
Moderador
Posts: 5024
Joined: Mon, 03 May 2004 3:08 pm
Location: Portland, OR USA
Contact:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

Interesting how much interpretation can generate a doubtful code without comments ... That's where we waste time, trying to guess what's on the head of the guy who did ..: roll:
Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest