Oracle Dual table trick

The other day I had to create a simple SELECT query. The query should return a single column result set or a default value if there was no data in the table. I know this would be a no brainer for somebody proficient in SQL, but I still find the solution neat enough to post it here.

SELECT NVL((SELECT COLUMN FROM TABLE WHERE KEY=VALUE), default_value)
  FROM DUAL;

Add new comment