我们可以在 WHERE 子句中对过程的参数之一添加空检查并避免代码块重复
select aa=t1.aa,bb=t2.bb ,cc=t3.cc
from t1,t2,t3,t4,t5
where t1.p1=t2.p1
and t2.p2=t3.p2
IF(procParameter IS NOT NULL)
and t3.p2=procParameter
and t4.p2=t5.p2
and t5.p3=t1.p2
看我想要一个 AND 有条件地执行,否则它根本不应该被执行..!!!!
我应该如何进行这种优化?我不想要代码重复
IF(procParameter IS NOT NULL)
begin
select aa=t1.aa,bb=t2.bb ,cc=t3.cc
from t1,t2,t3,t4,t5
where t1.p1=t2.p1
and t2.p2=t3.p2
and t3.p2=procParameter
and t4.p2=t5.p2
and t5.p3=t1.p2
end
Else
begin
select aa=t1.aa,bb=t2.bb ,cc=t3.cc
from t1,t2,t3,t4,t5
where t1.p1=t2.p1
and t2.p2=t3.p2
and t4.p2=t5.p2
and t5.p3=t1.p2
end
谢谢,