我有一个带有参数 name
的存储过程我想在 where
中使用子句匹配列的值,即类似
where col1 = name
现在当然这不匹配
null
至 null
因为路null
作品。我需要做吗where ((name is null and col1 is null) or col1 = name)
在这种情况下还是有更简洁的方法?
最佳答案
您可以使用 decode
功能如下:
where decode(col1, name, 0) is not null
从 SQL 引用中引用:
In a DECODE function, Oracle considers two nulls to be equivalent.
关于sql - 当我想在比较中使用空参数时,应该如何处理 PL/SQL 存储过程中的空参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4042496/