首页 文章

oracle plsql参数默认为null

提问于
浏览
0

我必须在列中使用参数,列不可为空 . 但参数默认为null . 我该如何控制空值 . 因为当我没有给出 Value 时,它正在考虑将值视为null并且我的脚本失败了 . 非常感谢您的帮助示例 -

create procedure test1(p_1 number default null)as begin select col1,col2 from table1 where col1 = p_1 - default NULL;结束; /

enter code here

1 回答

  • 1

    您可以使用 or 使查询过滤器成为条件:

    select col1, col2
    bulk collect into some_collectin
    from table1
    where p_1 is null or col1 = p_1
    

    如果 p_1 为null,或者因为没有传递参数或参数为null,则第一部分匹配 - 对于所有行 . 如果它不为null,则第一部分与任何行都不匹配,因此等同性检查将应用并仅过滤与参数匹配的行 .

    如果您有其他条件,请记住使用括号以确保整体逻辑正确:

    where (p_1 is null or col1 = p_1)
    and ...
    

相关问题