create or replace function getTerm(username_new varchar2(32))
return varchar2(10)
as
begin
result varchar2(10);
term number:=1;
yearCode varchar2(10):=substr(username_new,4,2);
semesterCode varchar2(10):=substr(username_new,6,1);
year number:=convert(number,yearCode);
currentdate date(7):=TO_DATE(to_char(getdate(),'YYYY-MM-DD'),'YYYY-MM-DD');
currentyear number:=convert(number,to_char(currentdate,'yyyy'));
lastyear number:=0;
d date(7):=TO_DATE(to_char(currentdate,'YYYY')+'-'+'03-16','YYYY-MM-DD');
newTermStartDate date(7);
lastTermEndDate date(7);
if currentdate<d then
lastyear:=1;
end if;
if lastyear=1 then
currentyear:=currentyear-1;
end if;
term:=(currentyear-year)*2;
newTermStartDate:=TO_DATE(to_char(currentdate,'YYYY')+'-09-16','YYYY-MM-DD');
lastTermEndDate:=TO_DATE(to_char(currentdate,'YYYY')+'-03-16','YYYY-MM-DD');
if currentdate<newTermStartDate then
if currentdate>lastTermEndDate then
term:=term+1;
end if;
else
term:=term+2;
end if;
if semesterCode=2 then
term:=term-1;
end if;
result:=convert(varchar2(10),term);
return result;
end getTerm;
这是我写的sql函数
下面是错误报告:
[Err] ORA-24344: success with compilation error
[Err] create or replace function getTerm(username_new varchar2(32))
return varchar2(10)
as
begin
result varchar2(10);
term number:=1;
yearCode varchar2(10):=substr(username_new,4,2);
semesterCode varchar2(10):=substr(username_new,6,1);
year number:=convert(number,yearCode);
currentdate date(7):=TO_DATE(to_char(getdate(),'YYYY-MM-DD'),'YYYY-MM-DD');
currentyear number:=convert(number,to_char(currentdate,'yyyy'));
lastyear number:=0;
d date(7):=TO_DATE(to_char(currentdate,'YYYY')+'-'+'03-16','YYYY-MM-DD');
newTermStartDate date(7);
lastTermEndDate date(7);
if currentdate<d then
lastyear:=1;
end if;
[Err] ORA-00900: invalid SQL statement
[Err] if lastyear=1 then
currentyear:=currentyear-1
[Err] ORA-00900: invalid SQL statement
[Err] end if
[Err] ORA-00900: invalid SQL statement
[Err] term:=(currentyear-year)*2
[Err] ORA-00900: invalid SQL statement
[Err] newTermStartDate:=TO_DATE(to_char(currentdate,'YYYY')+'-09-16','YYYY-MM-DD')
[Err] ORA-00900: invalid SQL statement
[Err] lastTermEndDate:=TO_DATE(to_char(currentdate,'YYYY')+'-03-16','YYYY-MM-DD')
[Err] ORA-00900: invalid SQL statement
[Err] if currentdate<newTermStartDate then
if currentdate>lastTermEndDate then
term:=term+1
[Err] ORA-00900: invalid SQL statement
[Err] end if
[Err] ORA-00900: invalid SQL statement