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 > What's wrong with this pl/sql procedure???

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-08-02, 16:31
hermasito hermasito is offline
Registered User
 
Join Date: Dec 2002
Posts: 3
Question What's wrong with this pl/sql procedure???

create or replace procedure upd_balance(
p_pnr number(2),p_amount number(7,2))

is
v_balance number(7,2);
v_pnr number(2) := p_pnr;
v_amount number(7,2) := p_amount;
begin
select balance into v_balance
from player
where pnr=v_pnr;

v_balance := v_balance+v_amount;

update player
set balance=v_balance
where pnr=v_nr;
end upd_balance;
/
Reply With Quote
  #2 (permalink)  
Old 12-08-02, 16:51
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Re: What's wrong with this pl/sql procedure???

Well, you have not shown the error message which would save me guessing! (Use SHOW ERROR) However, I can see the following errors:

1) you cannot specify scale and precision values for parameters, i.e. should just say:

create or replace procedure upd_balance(
p_pnr number,p_amount number)...

2) Variable v_nr is not declared - you meant v_pnr!

BTW, why are you copying the parameters into variables anyway? And why not just update without selecting first? Why not just:

create or replace procedure upd_balance(
p_pnr number,p_amount number)
is
begin
update player
set balance=balance+p_amount
where pnr=p_pnr;
end upd_balance;
/

Also, beware of NULL values - you may need to code:

set balance=NVL(balance,0)+NVL(p_amount,0)
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #3 (permalink)  
Old 12-08-02, 17:28
hermasito hermasito is offline
Registered User
 
Join Date: Dec 2002
Posts: 3
Lightbulb Re: What's wrong with this pl/sql procedure???

Thanks, dude!
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