0

我编写了一个程序,它使用游标来更新这些表中的某些行-这是程序:

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;

运行程序时,它卡在更新命令上。程序有什么问题?

4

2 回答 2

0
You need to add **FOR UPDATE** IN CURSOR TO UPDATE THE TABLE
于 2013-11-12T08:39:54.920 回答
0

为了更新游标内的表,您需要以“FOR UPDATE”模式打开游标,添加到您的查询“FOR UPDATE”:

(SELECT UNIQUE *
     FROM Sellers
    WHERE ID_Seller NOT IN (SELECT ID_Seller
                              FROM Sellers NATURAL JOIN Sales) FOR UPDATE);
于 2013-06-09T05:44:56.053 回答