Sql where子句中的开关大小写
我有一个下面的场景。你能纠正一下下面的问题吗Sql where子句中的开关大小写,sql,oracle,Sql,Oracle,我有一个下面的场景。你能纠正一下下面的问题吗 where l.au=m.acad_group and l.acad_prog = m.acad_prog case when acad_plan is not null then and l.acad_plan = m.acad_plan else and 0=0 end case case when l.acad_sub_plan is not null then and l.acad_sub_plan=m.acad_sub_pl
where l.au=m.acad_group
and l.acad_prog = m.acad_prog
case when acad_plan is not null then and l.acad_plan = m.acad_plan else and 0=0
end case
case when l.acad_sub_plan is not null then and l.acad_sub_plan=m.acad_sub_plan
else and 0=0 end case;
如果我理解正确,当 你可以试试这个 我有一个关于
acad\u计划为空的小问题
,您想检查l.acad\u计划
还是m.acad\u计划
where l.au=m.acad_group
AND l.acad_prog = m.acad_prog
AND (acad_plan is null OR( acad_plan is not null AND l.acad_plan = m.acad_plan))
AND (l.acad_sub_plan is null OR( l.acad_sub_plan is not null AND l.acad_sub_plan=m.acad_sub_plan))
在
WHERE
子句中,不要使用CASE WHEN
。使用和
和或
和括号
where l.au = m.acad_group
and l.acad_prog = m.acad_prog
and (and l.acad_plan = m.acad_plan or l.acad_plan is null)
and (and l.acad_sub_plan = m.acad_sub_plan or l.acad_sub_plan is null)
JOIN
条件应该在ON
子句中,而不是WHERE
子句中。学习使用正确的JOIN
语法。我已经删除了PL/SQL标记。PL/SQL是Oracle DBMS中用于触发器、函数等的编程语言,但您的查询仅限于SQL。WHERE子句中有CASE的有效用法,尤其是强制Oracle在一个谓词之前运行另一个谓词(例如,在对字符串执行to_数之前检查字符串仅包含数字)@Gary Myers:没错,尽管我宁愿为这种情况编写一个异常安全函数。对于TO_NUMBER
的特殊情况,我们甚至可以从Oracle 12c开始使用ON DEFAULT
选项。