![](/img/trans.png)
[英]PLSQL Procudure (Oracle) Comparing a variable in where clause
[英]Oracle PLSQL using a dynamic variable in a where clause
为了在 Toad 中进行测试,我有以下代码
select ...
from ...
where term_code = :termcode AND
(
case
when :theSubject is not null then SUBJ_CODE = :theSubject
else 1 = 1
end
)
AND ptrm_code <> 8
简而言之:如果未输入theSubject(为null),我想显示所有课程,否则我只想显示subject_code与Toad中变量window中输入的相同的课程。
但是我收到一个错误:[错误]执行(77:68):ORA-00905:此处缺少关键字:当:theCourse is not null then sect.SSBSECT_SUBJ_CODE = theCourse
任何解决此问题的意见将不胜感激。 谢谢
您可以使用 boolean 逻辑:
where
term_code = :termcode
and (:theSubject is null or subj_code = :theSubject)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.