set serveroutput on DECLARE CURSOR cemp is select ename ,sal from emp ; pename emp.ename%TYPE ; psal emp.sal%TYPE ; BEGIN OPEN cemp; LOOP FETCH cemp INTO pename,psal; EXIT WHEN cemp%notfound; dbms_output.put_line(pename||'的薪水是'||psal); END LOOP; CLOSE cemp; END;
set serveroutput on DECLARE CURSOR cemp is select empno ,job from emp ; pempno emp.empno%TYPE ; pjob emp.job%TYPE ; BEGIN OPEN cemp; LOOP FETCH cemp INTO pempno,pjob; EXIT WHEN cemp%notfound; if pjob='PRESIDENT' then update emp set sal=sal+1000 where empno=pempno; elsif pjob='MANAGER' then update emp set sal=sal+8000 where empno=pempno; else update emp set sal=sal+5000 where empno=pempno; end if; END LOOP; CLOSE cemp; commit; END; select * from emp
set serveroutput on DECLARE CURSOR cemp(dno number) is select ename from emp where empno=dno; pename emp.ename%TYPE ; BEGIN OPEN cemp(10); LOOP FETCH cemp INTO pename; exit when cemp%notfound; dbms_output.put_line(pename); END LOOP; CLOSE cemp; END;