首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

oracle函数错误

2014-01-28 
oracle函数错误:CREATE OR REPLACE FUNCTION CalWorkingDays ( StartDate in date, EndDate in date, Total

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 语句;它必须出现在一个循环中

------解决方法--------------------------------------------------------

SQL code
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是用在循环里面的

        

热点排行