|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Hello,
I seem to be having a problem with something very simple. The code is this: Code:
declare empNum number := 7934; cursor getSal is select sal from emp; salary number(7,2); avg number(7,2) := 0; amtOfEmps number := 0; diff number(7,2); begin --1)find out average salary of employee's dept open getSal; loop fetch getSal into salary; exit when getSal%notfound; avg := avg + salary; amtOfEmps := amtOfEmps + 1; end loop; close getSal; end; I have an error for this line: Code:
avg := avg + salary; The error is: Quote:
I have no idea why this comes up If anyone spots an error I would greatly appreciate if u could point it out. Thanks a lot |
|
#2
|
||||
|
||||
|
avg is a reserved word, it stands for the function average.
If you need the average salary of a department you can do something like: Table: |dept|emp|salary| select dept, avg(salary) from table group by dept
__________________
My blog Tutorials about OSS databases, DBMonster ... Contribute to OSS Development, fill bug reports! Developer Shed eSupport Commented my.ini/my.cnf (ADD YOUR OWN CONFIG TRICK) An introduction to database normalization Natural or Surrogate key Custom ordering for your results Correlated and uncorrelated subqueries Don't turn your outer joins into inner joins Random data (with a bias) |
|
#3
|
|||
|
|||
|
Quote:
u have used oracle keyword "avg: thats y it is showing an error |
|
#4
|
|||
|
|||
|
Quote:
u have used oracle keyword "avg" thats y it is showing an error |
![]() |
| Viewing: Dev Shed Forums > Databases > Oracle Development > basic addition problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|