gpt4 book ai didi

plsql - PLS-00103 函数结束时出错

转载 作者:行者123 更新时间:2023-12-01 23:06:55 25 4
gpt4 key购买 nike

收到与函数相关的以下错误:

'ERROR at line 20: PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: end not pragma final instantiable order overriding static member constructor map 0.01 seconds

CREATE OR REPLACE FUNCTION Function1
RETURN FLOAT
IS
PricePerBug FLOAT,
NumberOfBugs NUMBER,
TotalIncome FLOAT;
BEGIN
SELECT SUM(ProjectValue) INTO TotalIncome FROM tblProject;
SELECT COUNT(idBug) INTO NumberOfBugs FROM tblBug;
PricePerBug := (NumberOfBugs)/(TotalIncome);
RETURN PricePerBug;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No data found, no result to display; exception handled...');
WHEN TOO_MANY_ROWS THEN
RETURN 'Too many rows returned...';
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20015, 'Unknown exception in function Function1.');
END Function1;
/

任何建议表示赞赏...

最佳答案

声明应该全部以分号而不是逗号结尾:

PricePerBug FLOAT;
NumberOfBugs NUMBER;
TotalIncome FLOAT;

还有其他与此错误无关的异常处理问题:

  1. 如果曾经出现过 NO_DATA_FOUND(它不会)你会得到错误“ORA-06503: PL/SQL: 函数没有值(value)返回”因为你处理异常但不返回一个值。

  2. 如果曾经出现过 TOO_MANY_ROWS(不会出现),您将收到错误消息,因为您无法从仅返回 FLOAT 类型值的函数中返回文本“返回的行太多...” !

  3. 如果(可能)出现任何其他异常,您将不知道它是什么,因为您将有用的 Oracle 异常替换为您自己无用的“未知异常”消息。

此特定函数的错误处理的正确数量是无,即:

CREATE OR REPLACE FUNCTION Function1
RETURN FLOAT
IS
PricePerBug FLOAT;
NumberOfBugs NUMBER;
TotalIncome FLOAT;
BEGIN
SELECT SUM(ProjectValue) INTO TotalIncome FROM tblProject;
SELECT COUNT(idBug) INTO NumberOfBugs FROM tblBug;
PricePerBug := (NumberOfBugs)/(TotalIncome);
RETURN PricePerBug;
END Function1;

关于plsql - PLS-00103 函数结束时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5789961/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com