Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 18th, 2005, 07:45 PM
dancesport_warr's Avatar
dancesport_warr dancesport_warr is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 130 dancesport_warr User rank is Lance Corporal (50 - 100 Reputation Level)dancesport_warr User rank is Lance Corporal (50 - 100 Reputation Level)dancesport_warr User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Day 14 h 14 m 36 sec
Reputation Power: 5
Angry basic addition problem

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:
Encountered the symbol "+" when expecting one of the following:
(


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

Reply With Quote
  #2  
Old July 20th, 2005, 11:03 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,917 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 3 Days 14 h 31 m 53 sec
Reputation Power: 279
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

Reply With Quote
  #3  
Old July 25th, 2005, 05:30 AM
deepa.es deepa.es is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 2 deepa.es User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 51 m 17 sec
Reputation Power: 0
Quote:
Originally Posted by dancesport_warr
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:



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




u have used oracle keyword "avg: thats y it is showing an error

Reply With Quote
  #4  
Old July 25th, 2005, 05:30 AM
deepa.es deepa.es is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 2 deepa.es User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 51 m 17 sec
Reputation Power: 0
Quote:
Originally Posted by dancesport_warr
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:



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




u have used oracle keyword "avg" thats y it is showing an error

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > basic addition problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT