Skip to content
Advertisement

Checking the Oracle SQL DECODE function result against 0

I’m looking at some old PL/SQL code and I have dozen of DECODE functions written like this:

DECODE(value_1, value_2, 1, 0) = 0

Now, I know these DECODEs make comparison between value_1 and value_2 and they return true or false based on the outcome of comparison. But, for the love of coding, could someone please tell me what’s the logic behind = 0 part? Why is it necessary to check the return value against 0?

Advertisement

Answer

  • If value_1 = value_2, then decode returns 1
  • otherwise, it returns 0

Therefore, the whole expression checks whether value_1 is different from value_2 and then – I presume – does something.

If it is part of PL/SQL, you could rewrite it to


Some examples:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement