我编写了一个程序,它使用游标来更新这些表中的某些行 - 这是程序:
DECLARE
-- Local variables here
CURSOR s
IS
(SELECT UNIQUE *
FROM Sellers
WHERE ID_Seller NOT IN (SELECT ID_Seller
FROM Sellers NATURAL JOIN Sales));
s_rec Sellers%ROWTYPE;
BEGIN
-- Test statements here
OPEN s;
LOOP
FETCH s INTO s_rec;
EXIT WHEN s%NOTFOUND;
DBMS_OUTPUT.put_line (s_rec.ID_Seller);
DBMS_OUTPUT.put_line (s_rec.Salary);
updateSalary (s_rec.ID_Seller, s_rec.Salary - 50);
END LOOP;
CLOSE s;
END;
这是程序updateSalary:
CREATE OR REPLACE PROCEDURE updateSalary (ID_S IN VARCHAR2,
newSalary IN FLOAT)
IS
BEGIN
UPDATE Sellers s
SET s.salary = newSalary
WHERE s.ID_Seller = ID_S;
END updateSalary;
运行程序时,它会遇到更新命令。 该程序有什么问题?
答案 0 :(得分:0)
为了更新游标内的表格,你需要在“FOR UPDATE”模式下打开游标,添加到你的查询“FOR UPDATE”:
(SELECT UNIQUE *
FROM Sellers
WHERE ID_Seller NOT IN (SELECT ID_Seller
FROM Sellers NATURAL JOIN Sales) FOR UPDATE);
答案 1 :(得分:0)
You need to add **FOR UPDATE** IN CURSOR TO UPDATE THE TABLE