我有一个案例,在 2 个输入变量中,我将传递逗号分隔的电子邮件和用户 ID,或者其中一个或一个都不传递
现在的事情是程序将具有AND条件,如果电子邮件存在,它应该应用于过滤表的电子邮件列,对于用户ID也是如此
并且情况是数据库中的电子邮件和用户ID的值也为“null”,因此在nvl中,如果我们发送null,那么它将返回所有值,即使是那些持有null的值,然后它将采取“其中userid为null” "
例子:
userid. name
null. xyz
abc. null
adj. kak
例子 :
procedurename(phone in number, name in varchar2, userid in varchar2, cursor_c out sys_refcursor) is
begin
open cursor_c for
select name, email,mobile,phone, address, department,grade,scale
from employee where
user_id =nvl(select regexpr_str(userid,'[^,]+',1,level) from dual connect by regexpr_str(userid,'[^,]+',1,level) is not null),user_id))
and name=nvl(select regexpr_str(name,'[^,]+',1,level) from dual connect by regexpr_str(name,'[^,]+',1,level) is not null),name))
因此,如果我们将 NULL 作为参数传递,那么它甚至会选择“name=null”的行
不应该这样做,因为它会选择那些 name 为 null 但我们想要除 null 之外的所有这些 id
如果在输入参数为 null 的情况下选择了所有行,但排除具有 null 的值,那么如何做到这一点,否则它将使条件为 where name=null。