If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > update query in pl/sql

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-11-03, 15:05
zinny03 zinny03 is offline
Registered User
 
Join Date: Jul 2003
Posts: 5
update query in pl/sql

I want to update a query to populate the column COST with correct values. I am given the information that ODETAILS has a column called COST, whose value is the product of the quantity and price of the product being ordered. I have come up with a solution. Everything compiles fine, but when I go to check to see if the values have been populated, there is nothing under COST. I was wondering what the problem is. PRODUCTS is a table that has a column PRICE.

DECLARE

myprod PRODUCTS.PRICE%TYPE;

CURSOR product_cost IS
SELECT ODETAILS.COST
FROM ODETAILS, ORDERS, PRODUCTS
WHERE PRODUCTS.PNO = ODETAILS.PNO AND ORDERS.ONO = ODETAILS.ONO
FOR UPDATE OF ODETAILS.COST;


BEGIN
FOR product_rec IN product_cost

LOOP
UPDATE ODETAILS
SET ODETAILS.COST = (ODETAILS.QTY * myprod)
WHERE CURRENT OF product_cost;

END LOOP;

END;

/
Reply With Quote
  #2 (permalink)  
Old 07-11-03, 17:55
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,455
Cool

This looks kinda like homework, but what the heck, try this better:

UPDATE ODETAILS
SET COST = (
SELECT QTY * PRICE
FROM ORDERS, PRODUCTS
WHERE PRODUCTS.PNO = ODETAILS.PNO
AND ORDERS.ONO = ODETAILS.ONO );
Reply With Quote
  #3 (permalink)  
Old 07-11-03, 23:56
zinny03 zinny03 is offline
Registered User
 
Join Date: Jul 2003
Posts: 5
udpate query in pl/sql

Based on what you suggested, I tried this, and I'm getting a whole bunch of errors. I don't know what else to do. I declared both price and cost at the top, and I still get errors. This is what I did:

DECLARE

myprod PRODUCTS.PRICE%TYPE;

mycost ODETAISL.COST%TYPE;




BEGIN


UPDATE ODETAILS
SET COST = (SELECT QTY * PRICE
FROM ORDERS, PRODUCTS, ODETAILS
WHERE PRODUCTS.PNO = ODETAILS.PNO AND ORDERS.ONO = ODETAILS.ONO);






END;

/


Quote:
Originally posted by LKBrwn_DBA
This looks kinda like homework, but what the heck, try this better:

UPDATE ODETAILS
SET COST = (
SELECT QTY * PRICE
FROM ORDERS, PRODUCTS
WHERE PRODUCTS.PNO = ODETAILS.PNO
AND ORDERS.ONO = ODETAILS.ONO );
Reply With Quote
  #4 (permalink)  
Old 07-14-03, 12:05
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,455
Wink

What errors?

Post the complete procedure and error messages...
Reply With Quote
  #5 (permalink)  
Old 07-14-03, 13:07
izy izy is offline
Registered User
 
Join Date: Jul 2003
Posts: 10
I got it to work. Thanks.


Quote:
Originally posted by LKBrwn_DBA
What errors?

Post the complete procedure and error messages...
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On