CREATE OR REPLACE PROCEDURE CHECK_CREDITLIMIT
AS
    gesbetrag INTEGER;
    yesno customer.creditlimit_indicate%type;
CURSOR c IS SELECT cust.custid, cust.creditlimit
            FROM customer cust, ord o
            WHERE o.custid=cust.custid;
c_rec c%ROWTYPE;
BEGIN
    FOR c_rec IN c LOOP
       SELECT SUM(o.total) INTO gesbetrag FROM ord o
       WHERE c_rec.custid=o.custid;
       IF gesbetrag>c_rec.creditlimit THEN
           yesno := 'YES';
       ELSE
           yesno := 'NO';
       END IF;
       UPDATE customer cust SET CREDITLIMIT_INDICATE=yesno
       WHERE cust.custid=c_rec.custid;        
    END LOOP;
END CHECK_CREDITLIMIT;
/
