使用select语句替换sql中的空值?-change NULL为'No commission'

时间:2017-05-09 03:51:32

标签: sql oracle

Here is a screenshot

我需要删除佣金栏中的Null并将其更改为“No commission”。不知道如何编写该代码。我试图使用UPDATE或SET代码但是出错了。

这是我到目前为止的代码。

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;

3 个答案:

答案 0 :(得分:1)

尝试使用coalesce()或NVL()代替ISNULL()

SELECT ISNULL(COMMISSION_PCT, 'No commission')
FROM EMPLOYEES 

答案 1 :(得分:1)

对于Oracle使用:

NVL(pct_commission, 'No commission');

答案 2 :(得分:1)

结果的单个列中的所有值必须具有相同的数据类型。如果您想显示“无佣金”,这意味着您还需要将数字转换为字符串。在Oracle中,这是使用to_char()函数完成的。

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;