【发布时间】:2013-09-25 22:06:23
【问题描述】:
我有一个选择语句,其中 WHERE 子句的 IN 运算符。只要将某些值传递给问号(从 java 程序传递),查询就可以正常工作。但是当没有传递任何值时,我得到一个语法错误。
select
this_.categoryAddressMapId as category1_1_0_,
this_.categoryId as categoryId1_0_,
this_.addressId as addressId1_0_
from
icapcheckmyphotos.category_address_map this_ <br>
where
this_.addressId in (
?
)
当没有传递参数时,我需要设置null。请建议如何修改 where 子句。提前致谢
【问题讨论】:
-
括号中至少要有一个值,例如:
where foo in ()不是合法的 sql。它必须至少是where foo in (bar)。在不编写动态 sql 或输入至少一个您知道必须存在的值的情况下,您无法绕过此限制。 -
如果 Java 程序没有任何可取之处,是否应该调用此查询?似乎没有必要。