是否有可能使用 for 循环设置 if else 条件
例如
IF (emp_no IS NULL) then
for i in (select * from employees where emp_no= p_retval)
else
for i in (select * from employees where emp_no= p_retval_withcond)
end if;
当我尝试上述方法时,我遇到了编译错误。
问候
结构如下
IF (emp_no IS NULL) then
for i in (select * from employees where emp_no= p_retval)
loop
-- loop actions
end loop;
else
for i in (select * from employees where emp_no= p_retval_withcond)
loop
-- second loop actions
end loop;
end if;
for 循环是不可能的,但如果你在循环中的操作在这两种情况下是相似的,我会通过游标来做到这一点。
declare
cursor c1 is select * from employees where emp_no= p_retval;
cursor c2 is select * from employees where emp_no= p_retval_withcond;
ligne employees%rowtype;
.....
begin
IF (emp_no IS NULL) then
open c1;
ELSE
open C2;
END IF;
loop
IF (emp_no IS NULL) then
fetch C1 into ligne;
exit when c1%notfound;
ELSE
fetch C2 into ligne;
exit when c2%notfound;
END IF;
-- loop actions
....
end loop;
IF (emp_no IS NULL) then
close c1;
ELSE
close C2;
END IF;
end;