[英]Procedure never raise NO_DATA_FOUND Exception
i've created an procedure which increases salaries of peoples working in a department by a certain rate. 我创建了一个程序,可以将部门中工作人员的薪水按一定比例增加。 the department number and the rate are assed as parameters for the procedure.
部门编号和费率将作为该过程的参数。 Now, the procedure works great when i specify the good departement number, but once i specify a false one, and i'm waiting for the NO_DATA_FOUND Exception to raise, it never happen.
现在,当我指定正确的部门号时,该过程非常有效,但是一旦我指定了错误的部门号,并且我在等待引发NO_DATA_FOUND异常,就永远不会发生。 I searched tried many thing but didn't found the answer, so if you can help me i woul be really greatfull.
我搜索了很多东西,但没有找到答案,所以如果您可以帮助我,我将非常感激。 Thank you !
谢谢 ! Here is my code :
这是我的代码:
create or replace PROCEDURE AugmenteSalaire(numDepartement in departements.numerodepartement%TYPE, taux IN number) IS
p_nbreTotalSalaire employes.salaireemploye%type;
begin
SELECT sum(salaireemploye)
INTO p_nbreTotalSalaire
FROM employes
WHERE numerodepartement = numDepartement;
if taux > 0 AND taux <= 100 THEN
if p_nbreTotalSalaire < 150000 THEN
Update employes e
SET e.salaireemploye = e.salaireemploye + (e.salaireemploye * (taux * 0.01))
WHERE e.numerodepartement = numDepartement
AND NOT numeroemploye = (SELECT departements.chefdepartement from departements
WHERE departements.numerodepartement = numDepartement);
ELSE
DBMS_OUTPUT.PUT_LINE('Transaction refused : The salary sum cannot be above 150000');
END IF;
ELSE
DBMS_OUTPUT.PUT_LINE('The rate cannot be under 0 or aboce 100');
END IF;
Exception
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('The department number provided is invalid, '||
'please enter a valid department number(DEP001 for example)');
end;
SELECT sum(salaireemploye)
INTO p_nbreTotalSalaire
FROM employes
WHERE numerodepartement = numDepartement;
In this query you are using SUM()
. 在此查询中,您正在使用
SUM()
。 Now if there is no matching department, ie input "numDepartement" is a false department, sum(salaireemploye)
is 0 (no such department, so nothing to add, so 0). 现在,如果没有匹配的部门,即输入“ numDepartement”是错误的部门,则
sum(salaireemploye)
为0(没有此类部门,因此没有要添加的内容,因此为0)。
sum(salaireemploye)
thus has a valid value, which is 0 here. 因此,
sum(salaireemploye)
具有一个有效值,此处为0。 Hence this will never raise a NO_DATA_FOUND
exception 因此,这永远不会引发
NO_DATA_FOUND
异常
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.