Comparing Zeros in Oracle SQL

Is there a better way to compare if two values โ€‹โ€‹are equal, if they can be zeros other than the following?

a = b or (a is null and b is null) 
+6
source share
3 answers

You can:

 a=b or coalesce(a,b) is null 

You can also use nvl , but this is an obsolete function, and coalesce is faster because it stops when the first non-zero

+5
source

You can use DECODE(A,B,1) = 1

DECODE is irregular when handling NULL.

However, I think the intention is unclear and prefers vol7ron's answer. Clarity compared to the minimum character set!

+4
source

You can wrap it with nvl and set it to some value not expected in your set:

 NVL(a,0) = NVL(b,0) 
0
source

Source: https://habr.com/ru/post/891413/


All Articles