如果在where子句中传递的参数为空或null,如何编写n1ql查询以返回记录?
[{
"name": "John",
"age": 12
},
{
"name": "Smith",
"age": 12
},
{
"name": "Kevin",
"age": 15
}]
@Query("SELECT * FROM #{#n1ql.bucket} " +
"WHERE age = $1;")
List<Name> findByAge(Integer age);
预期: 如果年龄为空 返回
[{
"name": "John",
"age": 12
},
{
"name": "Smith",
"age": 12
},
{
"name": "Kevin",
"age": 15
}]
如果年龄为12 返回
[{
"name": "John",
"age": 12
},
{
"name": "Smith",
"age": 12
}]
答案 0 :(得分:1)
尝试一下
SELECT *
FROM default
WHERE age = $1 OR IFMISSINGORNULL($1,"") = "";