One Line IF Condition in PL / SQL
You can write IF ... ELSE ... END IF;
on one line, as others have shown; but no, you cannot do what you suggested and write "just like Java":
IF ( i.DECISAO_AT = 'S') ? 'PA' : 'I' ;
PL / SQL does not understand Java syntax ?
and :
and does not own the ternary operator as such. You can use what is described in the documentation . The closest thing to what I think you are asking for for this particular statement, anyway, might be case
:
CASE WHEN i.DECISAO_AT = 'S' THEN 'PA' ELSE 'I' END
Or maybe decode
, as xQbert already suggested in the comment. Also there is no "IF" though.
source to share
Of course you can, but down the road when you need to debug this if with multiple tests it will be a pain. Keep it on separate lines so it's easier to read, debug, comment on, and easier (and therefore cheaper) to service along the way. The next guy he works on will thank you.
I read in the book (I think it was "With elements of style") once: "Beware of smart, smart murders"). Keep it simple and lightweight. Code for the guy after you to maintain your code.
source to share