我正在尝试运行此代码,但它在“THEN”中给了我一个错误,我已经逐行检查了所有代码,似乎错误出现在 if 语句中,但我仔细检查了它。
我正在尝试比较事故发生的时间,以便能够将救护车送到最先发生的事故。我会很感激你的帮助
`create or replace function get_loc return location is
max NUMBER;
CURSOR accident_records IS
SELECT * FROM NEW_ACCIDENT;
accidentRec NEW_ACCIDENT_TYPE := NEW_ACCIDENT_TYPE (NULL,NULL,NULL,NULL);
ac_loc LOCATION := LOCATION (NULL,NULL);
type New_accident_rec_type is record
(
id number,
loc location,
TIME NUMBER,
SITUATION varchar2(60)
);
new_accident_rec New_accident_rec_type;
BEGIN
max:=0;
OPEN accident_records;
LOOP FETCH accident_records INTO new_accident_rec;
EXIT WHEN accident_records%NOTFOUND;
IF new_accident_rec.situation='not handled' then
IF new_accident_rec.time>max THEN
max:=new_accident_rec.time;
accidentRec.time:=new_accident_rec.time;
ac_loc:=new_accident_rec.loc;
END IF;
IF new_accident_rec.time<max THEN
ac_loc:=NULL;
END IF;
END IF;
END LOOP;
CLOSE accident_records;
dbms_output.put_line ('The time of Accident is: '||accidentRec.time || 'The location of the accident is: ' ||ac_loc);
RETURN ac_loc;
END;`