3

只是想知道是否有更好的方法在 ORACLE 中编写以下 PL/SQL 代码?

IF(p_c_courtesies_cd is not null 
OR  p_c_language_cd is not null
OR v_c_name is not null
OR v_c_firstname is not null
OR v_c_function is not null
OR p_c_phone is not null
OR p_c_mobile is not null
OR p_c_fax is not null
OR v_c_email is not null
) THEN
     -- Do something
END IF;
4

4 回答 4

9
If coalesce( expr1, expr2, ... expr_n ) is not null then do something end if;

看这里。

(感谢托尼的纠正)

于 2009-01-20T16:20:03.993 回答
2

我的回答是简单的“不”。

尽管有几种替代方法可以编写相同的构造,但我认为没有一种必然“更好”。

任何人都可以查看 IF 语句并确切地知道它的含义。基于连接或使用合并运算符的替代方案只是模糊了意图。

于 2009-01-20T23:34:44.100 回答
1

如果 coalesce(expr1,expr2,...exprn) 不为空,那么 ...

于 2009-01-20T16:24:59.740 回答
0

另一种方式,利用 Oracle 将 NULL 和 '' 视为相同的事实:

IF p_c_courtesies_cd 
   || p_c_language_cd 
   || v_c_name 
   || v_c_firstname 
   || v_c_function 
   || p_c_phone 
   || p_c_mobile p_c_fax 
   || v_c_email is not null
THEN
     -- Do something
END IF;
于 2009-01-20T16:57:01.937 回答