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:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old April 9th, 2004, 10:05 AM
Cokes Cokes is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Aberdeen, Scotland
Posts: 32 Cokes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 57 m 25 sec
Reputation Power: 5
Help needed - driving me nuts

i have a database made in oracle. I need to make a query that will take the price of a book, and the ISBN of a book. Find out how many of the same ISBN is in the database and calculates the price.

The only thing is that when i run my query.....it takes all the the ISBNs in the database, no matter if the ISBN is specified, it just takes the lot. Could someone have a lok at this query and see if there is anything obviously wrong.

Thanks in advance
Cokes


Quote:
CREATE OR REPLACE FUNCTION calculate_total_revenue
(ISBN IN book.ISBN%TYPE,
price IN book.price%TYPE)
RETURN number IS

total_revenue number;
number_of_sales number;

BEGIN
SELECT count(purchases.ISBN)
INTO number_of_sales
FROM purchases
WHERE purchases.ISBN = ISBN;

total_revenue:= (price * number_of_sales);
return (total_revenue);
END;

Reply With Quote
  #2  
Old April 9th, 2004, 11:56 AM
shafique shafique is offline
Senior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Canada
Posts: 305 shafique User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 45 m 20 sec
Reputation Power: 5
Don't make your function's argument name identical to your table column name, make the following changes:

CREATE OR REPLACE FUNCTION calculate_total_revenue
(P_ISBN IN book.ISBN%TYPE,
P_PRICE IN book.PRICE%TYPE)
RETURN number IS

total_revenue number;
number_of_sales number;

BEGIN
SELECT count(ISBN)
INTO number_of_sales
FROM purchases
WHERE purchases.ISBN = P_ISBN;

total_revenue:= (P_PRICE * number_of_sales);
return (total_revenue);
END;

Reply With Quote
  #3  
Old April 9th, 2004, 12:50 PM
Cokes Cokes is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Aberdeen, Scotland
Posts: 32 Cokes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 57 m 25 sec
Reputation Power: 5
Thumbs up

Thanks a lot buddy.......i'm useless with all this oracle stuff. Just another thing i gotta do for uni.

Thank you

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Help needed - driving me nuts


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 4 hosted by Hostway