oracle sql query statement NVL not working as desired -
i trying learn oracle sql , below query. wanted print everyone's manager , if doesn't manager should return "no one".
problem: getting blank statement instead of "no one". help?
select nvl(m.first_name || ' ' || m.last_name, 'no one') || ' supervises ' || w.first_name || ' ' || w.last_name employees w, employees m w.manager_id = m.employee_id(+); nvl(m.first_name||''||m.last_name,'noone')||'supervise ------------------------------------------------------ james smith supervises ron johnson ron johnson supervises susan jones ron johnson supervises fred hobbs supervises james smith
this because of reason, when m.first_name , m.last_name null manager, m.first_name || ' ' || m.last_name not result in null, ' '. so, print space instead of 'no one'. can achieve desired results using nvl2
select nvl2( m.first_name ||m.last_name , m.first_name || ' ' || m.last_name, 'no one' ) || ' supervises ' || w.first_name || ' ' || w.last_name employees w, employees m w.manager_id = m.employee_id(+);
Comments
Post a Comment