How to display a default value when no match found in a query?

前端 未结 1 504
[愿得一人]
[愿得一人] 2020-12-11 05:03

I want to display a default message when there is no data obtained from a query.

For example Let us take a query

select empname from employe

相关标签:
1条回答
  • 2020-12-11 05:25
    SELECT COALESCE((SELECT empname FROM employee WHERE id = 100), 'Unavailable')
    FROM   DUAL;
    

    You have to wrap the SELECT into another SELECT or no row will be returned. And where there is no row, there cannot be a value.

    0 讨论(0)
提交回复
热议问题