如何用文本替换空值? [英] How to replace null values with a text?
本文介绍了如何用文本替换空值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在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
,则还应该使用cast
或to_char
.
P.S. In case commision_pct
's datatype is not varchar
you should also use cast
or to_char
.
这篇关于如何用文本替换空值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文