Oracle中的if(condition,then,else) [英] if(condition, then, else) in Oracle

查看:143
本文介绍了Oracle中的if(condition,then,else)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MySQL/MSSQL具有一个简洁的内联if函数,您可以在查询中使用它来检测空值,如下所示.

MySQL/MSSQL has a neat little inline if function you can use within queries to detect null values, as shown below.

SELECT

...

foo.a_field AS "a_field",
SELECT if(foo.bar is null, 0, foo.bar) AS "bar",
foo.a_field AS "a_field",

...

我现在遇到的问题是,这段代码在Oracle数据库上运行并不安全,因为如果使用语法,似乎不支持此内联.

The problem I'm running into now is that this code is not safe to run on an Oracle database, as it seems not to support this inline if syntax.

Oracle中是否有等同的产品?

Is there an equivalent in Oracle?

推荐答案

使用标准的COALESCE函数:

Use the standard COALESCE function:

SELECT COALESCE(foo.bar, 0) as "bar", ...

或使用Oracle自己的NVL函数执行相同的操作.

Or use Oracle's own NVL function that does the same.

这篇关于Oracle中的if(condition,then,else)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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