我创建了一个程序。它给出了一个错误(ORA-01422:精确提取返回超过请求的行数)。至于特定的department_id,有多个员工。但是如何解决这个问题呢?
Create Procedure PP1
(ID in number, Percent in number, Sal out number, increase_sal out number) IS
Begin
Select salary, salary *(1+percent/100) into sal, increase_sal
From employees
where department_id= id;
DBMS_OUTPUT.PUT_LINE (sal || ' ' || increase_sal);
END;
/
Variable a number
Variable b number
Exec PP1 (100, 10, :a, :b)
Print a b
谢谢, Kuntal Roy
答案 0 :(得分:1)
我的猜测是你想要(未经测试的)
CREATE TYPE num_tbl IS TABLE OF NUMBER;
CREATE PROCEDURE raise_dept_salaries( p_dept_id IN employees.department_id%type,
p_raise_pct IN NUMBER,
p_old_sals OUT num_tbl,
p_new_sals OUT num_tbl )
AS
BEGIN
SELECT salary
BULK COLLECT INTO p_old_sals
FROM employees
WHERE department_id = p_dept_id;
UPDATE employees
SET salary = salary * (1 + p_raise_pct)
WHERE department_id = p_dept_id
RETURNING salary
BULK COLLECT INTO p_new_sals;
END;
现在,以这种方式拆分确实会引入其他会话可能会修改您的第一个SELECT
和您的UPDATE
之间的数据的可能性,因此这对于多个用户环境。当然,你真的不想首先返回旧工资和新工资,因为你已经知道他们将直接相互关联。如果您只返回了新工资的集合,那么您只需要一个UPDATE
语句就可以获得竞争条件。