我有接受某些参数的 plsql 程序,例如v_name、v_country、v_type。
我希望有一个带有这样的选择语句的游标:
select column from table1 t1, table2 t2
where t1.name = v_name
and t1.country = v_country
and t1.id = t2.id
and t2.type = v_type
如果某些参数为空,我只能将相关的 where 子句添加到游标吗?还是有更好的方法来实现这一点?
最佳答案
这不是您要直接问的,但它可能是一个可以接受的解决方案:
select column from table1 t1, table2 t2
where
(v_name is null or t1.name = v_name)
and (v_country is null or t1.country = v_country)
and t1.id = t2.id
and (v_type is null or t2.type = v_type)
关于oracle - 在oracle中将where子句动态添加到游标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/377464/