I need to display Employee last_name
and their commission amount from employees table in Oracle SQL, but the condition is if it encounter NULL
value I need to print "No Commission".
For the first part I wrote:
select last_name, commission_pct from employees;
But I am unable to get how to replace NULL
values with "No Commission".
For Oracle
For SQL
how if the condition like this:
and show all of the employee_id who has been working in there, if is it not, replacing into
varchar
You can use
case
expression:or
coalesce
:or
nvl
:P.S. In case
commision_pct
's datatype is notvarchar
you should also usecast
orto_char
.It is as simple as you can see, Isnull() Used to Replace NULL values to the default value we pass there, so what i did here is If "commission_pct" having NULL value then it'll replace that with "No Commission" text, which i have passed in ISNULL() as 2nd parameter.
select Last_Name, decode(nvl(salarycommission_pct,'0'),0,'No Commission',salarycommission_pct) as COMM from employees;
Another alternative, quite simple and precise:
Since,
commision_pct
is NUMBER data type,to_char
will explicitly convert it into string.