我在以下函数中收到数字或值错误
在以下行
acutalStartTime:=TO_CHAR (startTime, 'yyyy-mm-dd ');
谁能告诉我可能出了什么问题,谁能让我知道我是否可以写出更好的方法?
create or replace function dateDiff
( changeInStartTime out varchar2,acutalStartTime out varchar2 )
RETURN timestamp
IS
startTime timestamp;
v_start timestamp;
diffdays number;
findiff BOOLEAN;
diff number;
cursor c1 is
SELECT sometime from sometable;
BEGIN
changeInStartTime:='false';
v_start := TRUNC (SYSTIMESTAMP) + NUMTODSINTERVAL (1, 'second');
open c1;
fetch c1 into startTime;
Dbms_Output.Put_Line('value of query ' ||startTime);
if c1%notfound then
startTime := TO_TIMESTAMP('2012-01-01 00:00:00.001','yyyy-mm-dd hh24:mi:ss .ff3');
findiff:=false;
else findiff:=true;
end if;
--Dbms_Output.Put_Line('should we find diff' || findiff);
if findiff then
Dbms_Output.Put_Line('v_start ' || v_start);
Dbms_Output.Put_Line('startTime ' || startTime);
diff :=trunc(v_start) - trunc(startTime) ;
--diffdays:=extract(day from diff);
Dbms_Output.Put_Line('diff ' || diff);
Dbms_Output.Put_Line('diffdays ' || diffdays);
if diff > 1 then
changeInStartTime:='true';
startTime:=TRUNC (SYSTIMESTAMP-diff ) + NUMTODSINTERVAL (1, 'second');
else startTime:=v_start;
end if;
close c1;
end if;
acutalStartTime:=TO_CHAR (startTime, 'yyyy-mm-dd ');
RETURN startTime;
EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
END;