×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

PL/SQL variable problem (newbie!!!)

PL/SQL variable problem (newbie!!!)

PL/SQL variable problem (newbie!!!)

(OP)
   Hi,

   I'm a pl/sql newbie hitting a problem with a declared variable. Hopefully I'm doing something stupid and someone will be able to point it out. The variable in question from the code below is "total_mrp" - basically, as soon as I refer to it within the code (adding it to another field) it seems to 'disappear' - I've put displays in and until this line it shows up ok (as zero), but after the display brings nothing back, but the code loops the whole way through the cursor, so it's obviously going through the line but
nothing is happening and it's not falling over either.
   If anyone has any ideas, or if I canm give any further info, please let me know.
   Thanks in advance,

   Steve Burch


begin
  declare cursor c_shortfall is
  select part_nbr, mrp_qty, (1 - (mrp_qty / demand_qty )) * 100
Shortfall
  from shortfall
 where demand_qty != 0
 order by Shortfall desc
   for update;
  shortfall_rec c_shortfall%rowtype;
  total_mrp NUMBER (13,4) := 0;
begin
  open c_shortfall;
  loop
    fetch c_shortfall into shortfall_rec;
    exit when c_shortfall%notfound;
    total_mrp:= total_mrp + shortfall_rec.mrp_qty;
    update shortfall set mrp_tot_qty = total_mrp
     where current of c_shortfall;
  end loop;
  close c_shortfall;
end;
end;

RE: PL/SQL variable problem (newbie!!!)

Just a guess - are any of your values NULL ? The result of any numeric
operation involving a NULL value is NULL.

Try putting NVL(column, 0) around anything not defined as NOT NULL.

This is always the first think I check when it happens to me.

RE: PL/SQL variable problem (newbie!!!)

I think you have more begin's and end's than you need.

the structure of a plsql should be (and someone please correct me if I'm wrong)

declare
 cursor...
 total_mrp number....
 other_var ....
begin
 total_mrp := 0;
 other code....
end;

Mike
michael.j.lacey@ntlworld.com
Cargill's Corporate Web Site

RE: PL/SQL variable problem (newbie!!!)

Mike, the PL/SQL structure you give is correct, but it is possible to
embed one block inside another in the way Steve has. One reason would
be to give a routine it's own set of local variables, but it's not
used very often and seems a bit pointless in this case.
Also, I don't think this would make his variable disappear in the
middle of his code.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close