create or replace
FUNCTION CALCULATETIME
(
P_BOOKID IN number
) RETURN NUMBER AS
BEGIN
begin
declare
cursor v_borrow_time is select to_char(lendtime,'yyyy-mm-dd hh24:mi:ss') from reader_book_copy where bookid=P_BOOKID;
v_lendtime varchar;
v_cursortime date;
v_return number:=0;
v_temp number:=0;
loop
open v_borrow_time;--显示此处出错错误(15,6): PLS-00103: 出现符号 "V_BORROW_TIME"在需要下列之一时: := . ( @ % ; not null range default character
fetch v_borrow_time into v_lendtime;
exit when v_borrow_time%NOTFOUND;
select ceil((To_date(to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'), 'yyyy-mm-dd hh24-mi-ss') -
To_date(v_lendtime, 'yyyy-mm-dd hh24-mi-ss')) * 24) into v_temp FROM DUAL;
if v_temp >= v_return then
v_return:=v_temp;
END IF;
end loop;
close v_borrow_time;
RETURN v_return;
end;
FUNCTION CALCULATETIME
(
P_BOOKID IN number
) RETURN NUMBER AS
BEGIN
begin
declare
cursor v_borrow_time is select to_char(lendtime,'yyyy-mm-dd hh24:mi:ss') from reader_book_copy where bookid=P_BOOKID;
v_lendtime varchar;
v_cursortime date;
v_return number:=0;
v_temp number:=0;
loop
open v_borrow_time;--显示此处出错错误(15,6): PLS-00103: 出现符号 "V_BORROW_TIME"在需要下列之一时: := . ( @ % ; not null range default character
fetch v_borrow_time into v_lendtime;
exit when v_borrow_time%NOTFOUND;
select ceil((To_date(to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'), 'yyyy-mm-dd hh24-mi-ss') -
To_date(v_lendtime, 'yyyy-mm-dd hh24-mi-ss')) * 24) into v_temp FROM DUAL;
if v_temp >= v_return then
v_return:=v_temp;
END IF;
end loop;
close v_borrow_time;
RETURN v_return;
end;
2、打开游标 open v_borrow_time,应该放到loop 外边