declare cursor cemp is select empno ,sal from emp order by sal; --定義參數 pempno emp.empno%type; psal emp.sal%type; countEmp number :=0; salTotal number; begin --獲得工資總額的初始值 select sum(sal) into salTotal from emp; --打開光標 open cemp; loop -- 1.工資總額>5w exit when salTotal>50000; --取一個員工漲工資 fetch cemp into pempno ,psal; --2.%notfound exit when cemp%notfound; --漲工資 if salTotal+psal*1.1<50000 then update emp set sal = sal*1.1 where empno=pempno; --漲工資的人數 countEmp := countEmp+1; --漲後的工資總額 salTotal := salTotal+psal*0.1; else exit; end if; end loop; --關閉光標 close cemp; dbms_output.put_line('漲工資人數:'||countEmp|| '資總額:'||salTotal); end;