oracle - 在oracle中将where子句动态添加到游标

标签 oracle plsql database-cursor

我有接受某些参数的 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/

相关文章:

c# - 异步使用 ODP.NET

oracle - 检查 "it' 是否是 Oracle 中的数字”函数

Oracle 错误 ORA-06512

android - Android SQLiteDatabase 中的光标大小限制

oracle - 在 Oracle 中强制查询超时

sql - 选择 Oracle 字典 View 中可能不存在的列

sql - 识别何时在 SQL 查询或 PL/SQL 过程中执行函数

postgresql - 以表名为参数的游标更新记录

sql-server - sql 循环游标的替代方案是什么?

java - 如何在 Oracle 中全局(或按 session )限制结果集?