Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql where子句中的开关大小写_Sql_Oracle - Fatal编程技术网

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
选项。