0

Here is a screenshot

I need to remove the Null in the commission column and change it to 'No commission'. Not sure how to write that code. I tried to use UPDATE or SET code but got errors.

This is the code I got so far.

SELECT First_Name || ' ' || Last_Name AS "Full Name", ' NZD' || ' ' || SALARY AS "Salary", 
COMMISSION_PCT AS "COMMISSION_%",SALARY * COMMISSION_PCT AS "Commission"
FROM EMPLOYEES
ORDER BY LAST_NAME desc;
2
  • 1
    Possible duplicate of Replacing NULL with 0 in a SQL server query Commented May 9, 2017 at 3:53
  • I saw that post and try to do it using that code but keep getting error. Commented May 9, 2017 at 3:55

3 Answers 3

1

Try using coalesce() or NVL() for oracle instead of ISNULL()

SELECT ISNULL(COMMISSION_PCT, 'No commission')
FROM EMPLOYEES 
Sign up to request clarification or add additional context in comments.

4 Comments

I've changed my code like SELECT ISNULL (COMMISSION_PCT, "No commission"), First_Name || ' ' || Last_Name AS "Full Name", ' NZD' || ' ' || SALARY AS "Salary", COMMISSION_PCT AS "COMMISSION_%",SALARY * COMMISSION_PCT AS "Commission" FROM EMPLOYEES ORDER BY LAST_NAME desc; but I am still getting error.
ORA-00904: "ISNULL": invalid identifier 00904. 00000 - "%s: invalid identifier" *Cause: *Action: Error at Line: 18 Column: 9
try coalesce() or NVL() instead of isnull
@H.Cho Not the cause of this specific error message, but please note " and ' are not interchangeable.
1

All values in a single column of a result must be of the same data type. If you want to show "No commission" instead, that means you also need to convert the number into a string. In Oracle this is done using the to_char() function.

SELECT First_Name || ' ' || Last_Name AS "Full Name", 
       ' NZD' || ' ' || SALARY AS "Salary", 
       COMMISSION_PCT AS "COMMISSION_%",
       nvl(to_char(salary * commission_pct, 'FM9999.99'), 'No Commission') AS "Commission"
FROM EMPLOYEES
ORDER BY LAST_NAME desc;

Comments

1

For Oracle use:

NVL(pct_commission, 'No commission');

3 Comments

how do we use that code? Do I just add on to SELECT section? SELECT First_Name || ' ' || Last_Name AS "Full Name", ' NZD' || ' ' || SALARY AS "Salary", COMMISSION_PCT AS "COMMISSION_%",SALARY * COMMISSION_PCT AS "Commission", NVL(pct_commission, 'No commission') FROM EMPLOYEES ORDER BY LAST_NAME desc; like this?
Try this: SELECT First_Name || ' ' || Last_Name AS "Full Name", ' NZD' || ' ' || SALARY AS "Salary", NVL(COMMISSION_PCT, 'No commission') AS "COMMISSION_%",SALARY * NVL(COMMISSION_PCT, 0) AS "Commission" FROM EMPLOYEES ORDER BY LAST_NAME desc;
Well, yeah. Ideally, you would replace null with 0 instead of "No commision" so the types would match up. Will probably need to use to_char() to convert everything to a string: SELECT First_Name || ' ' || Last_Name AS "Full Name", ' NZD' || ' ' || SALARY AS "Salary", COMMISSION_PCT, AS "COMMISSION_%",SALARY * NVL(TO_CHAR(COMMISSION_PCT), 0) AS "Commission" FROM EMPLOYEES ORDER BY LAST_NAME desc;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.