我希望有一个过程,它接受3个employee_id作为参数然后比较它们,最低和最高将被交换,而中间的一个被留下。我不确定我是否正确接近这个,我在if else部分继续在oracle apex上出错。我读过可能更容易实现案例陈述? - 注意:这是一个家庭作业问题 到目前为止我所拥有的:
create or replace procedure myproc(empid in number, empid in number, empid in number) is
originalsalary1 employees.salary%type;
originalsalary2 employees.salary%type;
originalsalary3 employees.salary%type;
newsalary employees.salary%type;
begin
select salary INTO originalsalary1 from employees
where employee_id = empid;
select salary INTO originalsalary2 from employees
where employee_id = empid;
select salary INTO originalsalary3 from employees
where employee_id = empid;
if originalsalary1 <= originalsalary2 and originalsalary3 then
newsalary := originalsalary1 * 1.1;
elseif originalsalary2 <= originalsalary1 and originalsalary3 then
newsalary := originalsalary2 * 1.1;
elseif originalsalary3 <= originalsalary1 and originalsalary2 then
newsalary := originalsalary3 * 1.1;
end if;
end;
/
答案 0 :(得分:1)
CREATE OR REPLACE PROCEDURE PR_PREP(EMPID1 IN INT, EMPID2 IN INT , EMPID3 IN
INT)
IS
MAX_SAL_EMP_ID INT;
MIN_SAL_EMP_ID INT;
MAX_SAL EMPLOYEES.SALARY%TYPE;
MIN_SAL EMPLOYEES.SALARY%TYPE;
BEGIN
SELECT EMP_ID , SALARY INTO MAX_SAL_EMP_ID , MAX_SAL FROM EMPLOYEES WHERE
EMP_ID IN (EMPID1, EMPID2, EMPID3)
AND SALARY = (SELECT MAX(SALARY) FROM EMPLOYEES WHERE EMP_ID IN (EMPID1,
EMPID2, EMPID3));
SELECT EMP_ID , SALARY INTO MIN_SAL_EMP_ID , MIN_SAL FROM EMPLOYEES WHERE
EMP_ID IN (EMPID1, EMPID2, EMPID3)
AND SALARY = (SELECT MIN(SALARY) FROM EMPLOYEES WHERE EMP_ID IN (EMPID1,
EMPID2, EMPID3));
UPDATE EMPLOYEES SET SALARY = MAX_SAL WHERE EMP_ID = MIN_SAL_EMP_ID;
UPDATE EMPLOYEES SET SALARY = MIN_SAL WHERE EMP_ID = MAX_SAL_EMP_ID;
COMMIT;
END;