如何用文本替换空值? [英] How to replace null values with a text?

查看:105
本文介绍了如何用文本替换空值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Oracle SQL中显示雇员last_name及其来自雇员表的佣金金额,但条件是如果遇到NULL值,我需要打印无佣金" . br> 在第一部分中,我写道:

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;

但是我无法获得如何用无佣金" 替换NULL值.

But I am unable to get how to replace NULL values with "No Commission".

推荐答案

您可以使用case表达式:

select last_name
     , case when commision_pct is null then 'No Commission' else commision_pct end    
from employees;

coalesce:

select last_name
     , coalesce(commision_pct, 'No Commission')
from employees;

nvl:

 select last_name
     , nvl(commision_pct, 'No Commission')
from employees;

P.S.如果commision_pct的数据类型不是varchar,则还应该使用castto_char.

P.S. In case commision_pct's datatype is not varchar you should also use cast or to_char.

这篇关于如何用文本替换空值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆