I have a query like this:
select empno,name
from emp
where job = 'CLERK'
and empno = :empno
If I pass empno that is null I would like to display all the records that match the condition of job = 'CLERK'. If empno is a specific number then it should filter for job and empno.
Anyway to do this in SQL without using PLSQL?
and (empno = :empno or :empno is null)
Something like this if pass parameter is null than replace it with the actual column value ...
select empno,name from emp where
job = 'CLERK'
and empno = NVL(:empno ,empno)
How NVL work
The syntax for the NVL function is:
NVL( string1, replace_with )
string1 is the string to test for a null value.
replace_with is the value returned if string1 is null.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With