oracle函数错误:
CREATE OR REPLACE FUNCTION CalWorkingDays
(
StartDate in date,
EndDate in date,
TotalDays in integer
)
RETURN integer IS
v_id int;
FreeDays integer;
DaoJiS integer;
BEGIN
if TotalDays <>0 then
v_id:=-1;
dbms_output.put_line('The value of TotalDays must be up to 0');
exit;
end if;
if TotalDays <FreeDays then
v_id:=-1;
exit;
end if;
if StartDate>EndDate then
v_id:=-1;
exit;
end if;
select count(*) into FreeDays from V_JIEJIARI where jiejiari between StartDate and EndDate;
DaoJiS := TotalDays - FreeDays;
RETURN DaoJiS;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
WHEN OTHERS THEN
RAISE;
END CalWorkingDays;
/
PLS-00376: 非法 EXIT 语句;它必须出现在一个循环中
------解决方法--------------------------------------------------------
Oracle已经提示说了必须存在一个循环中 ...Consult code below: LOOP FETCH c1 INTO c1_rec; EXIT WHEN c1%NOTFOUND; IF c1_rec.teamcode = tmpstr1 THEN retVal := 1; EXIT; END IF; END LOOP;
------解决方法--------------------------------------------------------
提示,先把程序的结构写完整了,然后 在加业务逻辑
------解决方法--------------------------------------------------------
不用这么写 ,直接
return v_id ;代替exit就可以了
exit是用在循环里面的