我正在使用与emp表相同的emp3表。
DECLARE
CURSOR incr_cur IS SELECT * FROM emp3 FOR UPDATE OF sal;
v_job emp3.job%TYPE := '&ENTER_Job';
v_cnt INTEGER;
BEGIN
FOR r_l IN incr_cur LOOP
IF v_job = r_l.job THEN
UPDATE emp3 SET sal = sal + 100 WHERE CURRENT OF incr_cur;
END IF;
END LOOP;
FOR p_l IN incr_cur LOOP
IF v_job = p_l.job THEN
DBMS_OUTPUT.PUT_LINE('The Salary of ' || p_l.ename || ' is: ' || p_l.sal || ' (Incremented).');
ELSE
DBMS_OUTPUT.PUT_LINE('The Salary of ' || p_l.ename || ' is: ' || p_l.sal || ' (Not Incremented).');
END IF;
END LOOP;
END;
答案 0 :(得分:1)
只需在if
条件后递增一个变量,然后在结尾显示它。
DECLARE
CURSOR ..
..
v_cnt INTEGER;
BEGIN
..
..
FOR p_l in incr_cur --second for loop
LOOP
IF v_job = p_l.job
v_cnt := v_cnt + 1;
..
END LOOP;
DBMS_OUTPUT.PUT_LINE('The Salary of '||v_cnt||' Employees are Incremented by 100');
END;
答案 1 :(得分:0)
DECLARE
CURSOR incr_cur IS SELECT * FROM emp3 FOR UPDATE OF sal;
v_job emp3.job%TYPE := '&ENTER_Job';
v_cnt INTEGER := 0;
BEGIN
FOR r_l IN incr_cur LOOP
IF v_job = r_l.job THEN
UPDATE emp3 SET sal = sal + 100 WHERE CURRENT OF incr_cur;
END IF;
END LOOP;
FOR p_l IN incr_cur LOOP
IF v_job = p_l.job THEN
v_cnt := v_cnt + 1;
DBMS_OUTPUT.PUT_LINE('The Salary of ' || p_l.ename || ' is: ' || p_l.sal || ' (Incremented).');
ELSE
DBMS_OUTPUT.PUT_LINE('The Salary of ' || p_l.ename || ' is: ' || p_l.sal || ' (Not Incremented).');
END IF;
END LOOP;
DBMS_OUTPUT.PUT_LINE('The Salary of '|| v_cnt ||' Employees are Incremented by 100');
END;