Declare
Cursor avg_cursor Is Select e.deptno,dname,Avg(sal) ,Count(empno)
From emp e ,dept d
Where e.deptno = d.deptno
Group By e.deptno,d.dname
Having Avg(sal)>1000;
v_deptno dept.deptno%Type;
v_dname dept.dname%Type;
v_avgsal emp.sal%Type;
v_count Number;
Begin
Open avg_cursor;
Loop
Fetch Avg_cursor Into v_deptno,v_dname,v_avgsal,v_count ;
Exit When avg_cursor%Notfound;
dbms_output.put_line('部门编号为'||v_deptno'||的部门名称为'||v_dname||',其平均工资为:'||v_avgsal||',人数为'||v_count);
End Loop;
Close avg_cursor;
End;
Begin
For avg_record In ( Select ename,dname From emp e ,dept d Where e.deptno = d.deptno(+) ) Loop
dbms_output.put_line('部门编号为'||avg_record.ename||'的部门名称为'||avg_record.dname);
End Loop;
End;
Declare
Cursor sumsal_cursor Is Select Sum(sal) sumsal,deptno From emp Group By deptno For Update;
Begin
For r_1 In sumsal_cursor Loop
If r_1.sumsal >10000 Then
Update emp Set sal = sal*1.1 Where deptno = r_1.deptno;
Else
Update emp Set sal = sal*1.2 Where deptno = r_1.deptno;
End If;
End Loop;
End ;