在where子句中使用动态变量的oracle plsql

yhqotfr8  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(354)

对于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

简而言之:如果主题没有输入(为空),我想显示所有的课程,否则我只想显示那些主题代码与toad变量窗口中输入的相同的课程。
但是我得到一个错误:[error]execution(77:68):ora-00905:这里缺少关键字:when:thecourse不为空,那么sect.ssbsect\u subject\u code=thecourse
对解决这个问题的任何意见都将不胜感激。谢谢

368yc8dk

368yc8dk1#

可以使用布尔逻辑:

where 
    term_code = :termcode 
    and (:theSubject is null or subj_code = :theSubject)

相关问题