0

job_id我的代码检索用户指定的最高薪水和员工人数。这是 oracle 10g express edition 中的一个 SQL 代码,现在您认为我应该在我的代码中添加问号以创建一个异常处理程序,该处理程序将检测何时有两名员工在指定的薪水最高job_id...请帮帮我,你认为我应该在我的异常部分的问号上使用什么关键字?

DECLARE

lvn_emp_tot    NUMBER;
lvn_max_sal    NUMBER;
lvc_jb_id      VARCHAR2(30) := :JOB_ID;


BEGIN

  SELECT job_id, max(salary), count(job_id)
    INTO lvc_jb_id, lvn_max_sal, lvn_emp_tot
    FROM Employees
   WHERE job_id = lvc_jb_id
   GROUP BY job_id; 

  DBMS_OUTPUT.PUT_LINE('Maximum salary:  '||lvn_max_sal);
  DBMS_OUTPUT.PUT_LINE('Number of Employees: '||lvn_emp_tot);

EXCEPTION
    WHEN ? THEN 
    DBMS_OUTPUT.PUT_LINE('More than one employee has the highest salary');

END;
4

1 回答 1

0

在此之前更改您的查询:

select job_ID,salary,count(*) INTO lvc_jb_id, lvn_max_sal, lvn_emp_tot 
from Employees
where salary= (
                 SELECT max(salary)
                 FROM Employees
                 WHERE job_id = input_jobid
                 GROUP BY job_id
              )
group by job_ID; 

在声明块中:

ex_custom EXCEPTION;

并在查询后:

if lvn_emp_tot>1 then
    raise ex_custom ;    
end if;

毕竟这一切:

?=ex_custom;)

于 2012-11-26T06:31:08.460 回答