PLS-00103:预期出现以下情况之一时遇到符号"THEN"



我正在尝试运行此代码,但它在"然后"中给了我一个错误我仔细检查了一下。

我试图比较事故的时间,以便我能够将救护车寄给首先发生的事故。感谢您的帮助

`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;`

问题是您有一个名为max的本地变量,该变量与Oracle MAX汇总函数冲突。

出现错误是因为Oracle认为(字符是在max之后出现的,但是它看到THEN。我看到的错误的全文是

LINE/COL ERROR
-------- -----------------------------------------------------------------
22/42    PLS-00103: Encountered the symbol "THEN" when expecting one of
         the following:
         (

(在运行之前,我可能已经对您的代码进行了重新格式化;不用担心行/列号是否不匹配。)

在PL/SQL中,通常是将局部变量带有l_v_是个好主意。除了避免使用MAX之类的Oracle内置功能外,它还可以帮助您避免使用与您的本地变量相同的列名称冲突。

希望如果您将max变量重命名为l_max,则汇编错误应该消失。

相关内容

最新更新