Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
SQL> select last_name||', '||first_name emp,dept_id
2 from emp;
Employee
Name DEPT_ID
------------------------------ ----------
Velasquez, Carmen 50
Ngao, LaDoris 41
Nagayama, Midori 31
Quick-To-See, Mark 10
Ropeburn, Audry 50
Urguhart, Molly 41
Menchu, Roberta 42
SQL> select id,name from dept;
ID NAME
---------- -------------------------
10 Finance
31 Sales
32 Sales
33 Sales
34 Sales
35 Sales
41 Operations
42 Operations
43 Operations
44 Operations
45 Operations
50 Administration
51 Information Tech
Next, assume we wish to print a DEPARTMENT report that shows ALL Departments and their Employees (including Departments that have no Employees). Here is a standard query to produce a department report:
SQL> select d.id,name, decode(last_name,null,null,last_name||', '||first_name) Emp
2 from emp e, dept d
3 where e.dept_id = d.id
4 /
Employee
ID NAME Name
---------- ------------------------- ------------------------------
10 Finance Quick-To-See, Mark
31 Sales Nagayama, Midori
41 Operations Ngao, LaDoris
41 Operations Urguhart, Molly
42 Operations Menchu, Roberta
50 Administration Velasquez, Carmen
50 Administration Ropeburn, Audry
Notice we see only rows "where dept_id = d.id". Since there are departments with no matching employees, we do not see those "empty" departments.
To get those rows to print out, we must tell Oracle that we have REAL departments for which we need GHOST employees. And what is the best symbol to represent ghosts? How about a tombstone with a cross on it -- "(+)". This symbol tells Oracle to "manufacture" a ghost employee wherever there is a department with no matching employees:
SQL> select d.id,name, decode(last_name,null,null,last_name||', '||first_name) Emp
2 from emp e, dept d
3 where e.dept_id(+) = d.id
4 /
Employee
ID NAME Name
---------- ------------------------- ------------------------------
10 Finance Quick-To-See, Mark
31 Sales Nagayama, Midori
32 Sales
33 Sales
34 Sales
35 Sales
41 Operations Ngao, LaDoris
41 Operations Urguhart, Molly
42 Operations Menchu, Roberta
43 Operations
44 Operations
45 Operations
50 Administration Velasquez, Carmen
50 Administration Ropeburn, Audry
51 Information Tech
SQL>