PLSQL提取不会退出

问题描述 投票:0回答:1

具有此员工表:enter image description here

和一个plsql查询:

DECLARE
    totaal_salaris    INT := 0;
    CURSOR medewerker_cur IS
      SELECT naam, maandsal
      FROM MEDEWERKERS;
      medewerker_row    medewerker_cur%rowtype;
BEGIN  
    OPEN medewerker_cur;
    LOOP
      FETCH medewerker_cur INTO medewerker_row;
      EXIT WHEN medewerker_cur%NOTFOUND OR totaal_salaris > 50000;
      UPDATE medewerkers
        SET maandsal = (medewerker_row.maandsal * 1.10)
        WHERE naam = medewerker_row.naam;
      totaal_salaris := totaal_salaris + medewerker_row.maandsal;
    END LOOP;
    dbms_output.put_line('Totaal uit te keren salaris: ' || totaal_salaris);
END;
/

意图是在总工资<50.000的前提下,将所有现有员工的工资(基本工资)提高10%。但这根本无法解决。.

我3仔细检查了运行脚本的女巫,这是我得到的结果:

一些测试结果:

首次运行:

PL / SQL过程成功完成。Totaaluit te keren salaris:55000

强制转换为5500;

第二时间

PL / SQL过程成功完成。Totaaluit te keren salaris:55000

强制转换为6050

第三次

PL / SQL过程成功完成。总工资:54450

强制转换为6655

oracle plsql
1个回答
0
投票

这应该是解决方案。

DECLARE
    total_salaris    INT := 0;

    CURSOR employee_cur IS
      SELECT employee_id, first_name, salary
      FROM employees;

    employee_rec   employee_cur%rowtype;

BEGIN  
    OPEN employee_cur;
    LOOP
      FETCH employee_cur INTO employee_rec;

      EXIT WHEN employee_cur%NOTFOUND OR total_salaris > 50000;

      UPDATE employees
        SET salary = (employee_rec.salary * 1.10)
        WHERE employee_id = employee_rec.employee_id;

      total_salaris := total_salaris + (employee_rec.salary * 1.1);

    END LOOP;
    dbms_output.put_line('Totaal uit te keren salaris: ' || total_salaris);
END;
© www.soinside.com 2019 - 2024. All rights reserved.