Drop and create a new table, run the PL/SQL, and then check to see that the data is there.
Drop Table Dept_Stats;
Create Table Dept_Stats
( DName Varchar2(10) Primary Key
, TotCnt Number (3)
, TotSal Number (8,2)
, AvgSal Number (8,2)
);
--+----------------------------------------------------
--| Declaration Section - Define Department Stats
--+----------------------------------------------------
Declare
Cursor c_DeptStats Is
Select DName
, Count(*) EmpCnt
, Sum(Sal) SumSal
, Avg(Sal) AvgSal
From Dept d, Emp e
Where d.Deptno = e.Deptno
Group By DName
Order By DName;
--+----------------------------------------------------
--| Execution: Loop to read records in cursor
--+----------------------------------------------------
Begin
For v_Ctr In c_DeptStats Loop
Insert Into Dept_Stats
Values ( v_Ctr.DName
, v_Ctr.EmpCnt
, v_Ctr.SumSal
, v_Ctr.AvgSal);
End Loop;
Commit;
End;
/
Select *
From Dept_Stats;
No comments:
Post a Comment