Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PL/SQL variable problem (newbie!!!)

Status
Not open for further replies.

SteveBurch

Programmer
Jul 17, 2000
5
0
0
BM
&nbsp;&nbsp;&nbsp;Hi,<br><br>&nbsp;&nbsp;&nbsp;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 &quot;total_mrp&quot; - 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<br>nothing is happening and it's not falling over either.<br>&nbsp;&nbsp;&nbsp;If anyone has any ideas, or if I canm give any further info, please let me know.<br>&nbsp;&nbsp;&nbsp;Thanks in advance,<br><br>&nbsp;&nbsp;&nbsp;Steve Burch<br><br><br>begin<br>&nbsp;&nbsp;declare cursor c_shortfall is<br>&nbsp;&nbsp;select part_nbr, mrp_qty, (1 - (mrp_qty / demand_qty )) * 100<br>Shortfall<br>&nbsp;&nbsp;from shortfall<br>&nbsp;where demand_qty != 0<br>&nbsp;order by Shortfall desc<br>&nbsp;&nbsp;&nbsp;for update;<br>&nbsp;&nbsp;shortfall_rec c_shortfall%rowtype;<br>&nbsp;&nbsp;total_mrp NUMBER (13,4) := 0;<br>begin<br>&nbsp;&nbsp;open c_shortfall;<br>&nbsp;&nbsp;loop<br>&nbsp;&nbsp;&nbsp;&nbsp;fetch c_shortfall into shortfall_rec;<br>&nbsp;&nbsp;&nbsp;&nbsp;exit when c_shortfall%notfound;<br>&nbsp;&nbsp;&nbsp;&nbsp;total_mrp:= total_mrp + shortfall_rec.mrp_qty;<br>&nbsp;&nbsp;&nbsp;&nbsp;update shortfall set mrp_tot_qty = total_mrp<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;where current of c_shortfall;<br>&nbsp;&nbsp;end loop;<br>&nbsp;&nbsp;close c_shortfall;<br>end;<br>end;
 
Just a guess - are any of your values NULL ? The result of any numeric<br>operation involving a NULL value is NULL.<br><br>Try putting NVL(column, 0) around anything not defined as NOT NULL.<br><br>This is always the first think I check when it happens to me.
 
I think you have more begin's and end's than you need.<br><br>the structure of a plsql should be (and someone please correct me if I'm wrong)<br><br>declare<br>&nbsp;cursor...<br>&nbsp;total_mrp number....<br>&nbsp;other_var ....<br>begin<br>&nbsp;total_mrp := 0;<br>&nbsp;other code....<br>end;<br> <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Mike, the PL/SQL structure you give is correct, but it is possible to<br>embed one block inside another in the way Steve has. One reason would<br>be to give a routine it's own set of local variables, but it's not<br>used very often and seems a bit pointless in this case.<br>Also, I don't think this would make his variable disappear in the<br>middle of his code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top