Home » SQL & PL/SQL » SQL & PL/SQL » how to written some default value from sql query
how to written some default value from sql query [message #282018] Tue, 20 November 2007 07:31 Go to next message
miroconnect@yahoo.com
Messages: 202
Registered: April 2006
Senior Member
I have a simple query
select name from employees where employee_id=5

suppose there was no 5 the query would not return anything
is there a way to return default value in case of no records ?
Re: how to written some default value from sql query [message #282022 is a reply to message #282018] Tue, 20 November 2007 07:38 Go to previous message
Michel Cadot
Messages: 68718
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
First way:
SQL> select ename from (
  2  select 1 c1, ename from emp where empno=5
  3  union all
  4  select 2 c1, 'default value' from dual
  5  order by c1
  6  )
  7  where rownum=1
  8  /
ENAME
-------------
default value

1 row selected.

Waiting for others... Wink

Regards
Michel
Previous Topic: return comma seperated values
Next Topic: OPtions
Goto Forum:
  


Current Time: Mon Dec 02 08:11:32 CST 2024