Having trouble with inner for loop values in my procedure

Hi ...
I am using oracle 10g and here is my procedure ...
create or replace procedure sales_information is
v_qty number(10);
rem_qty number(10):=0;
cursor pck_quantity is
select * from sales_info;
cursor no_of_labels is
select ceil(sum(nvl(total_quantity,actual_quantity))/400) from sales_info;
begin
for j in no_of_labels
loop
for i in pck_quantity
loop
select nvl(i.total_quantity,i.actual_quantity) into v_qty from sales_info;
if v_qty>=i.packed_quantity and rem_qty=0 then
insert into sales_order values------------
rem-qty:=v_qty-i.packed_quantity;
v_qty:=rem_qty;
exit;
else if v_qty>=i.packed_quantity and rem_qty>=400 then
insert into sales_order values-----------
rem_qty:=v_qty-rem_qty;
v_qty:=rem_qty;
exit;
else if v_qty>=i.packed_quantity and rem_qty>0 then
rem_qty:=v_qty+rem_qty-i.packed_quantity;
v_qty:=rem_qty;
insert into sales_order values-----------
else if v_qty is null and rem_qty>0 and then
insert into sales_order values-----------
else if v_qty<i.packed_quantity and rem_qty:=0 then
rem_qty:=v_qty;
else if v_qty<i.packed_quantity and rem_qty>0 then
if (v_qty+rem_qty)>400 then
insert into sales_order values-----------
rem_qty:=v_qty+rem_qty-i.packed_quantity;
v_qty:=rem_qty;
end if;
end if;
end loop;
end loop;
The inner for loop will retrieve the same values of v_qty for every iteration of outer for loop when it runs the following select statement:
select nvl(i.total_quantity,i.actual_quantity) into v_qty from sales_info;
and thus loses the previously computed values of v_qty and rem_qty
in the previous iteration of outer for loop whereas i want the inner for loop to iterate over it's previously computed values of v_qty and rem_qty but cant think of a workaround.

h4. Thanks Dave for explanation. Hope I understood your requirement and below code resolves that
-- Creating table SALES_INFO
CREATE TABLE SALES_INFO
(    S_NO             NUMBER(1),
     ACTUAL_QUANTITY  NUMBER(10),
     TOTAL_QUANTITY   NUMBER(10),
      PACKED_QUANTITY  NUMBER(10)
-- Creating table sales_order
CREATE TABLE SALES_ORDER
(    S_NO             NUMBER(1),
     LABEL            VARCHAR2(30),
     ORDER_QUANTITY   NUMBER(10)
-- Push SALES_INFO data
INSERT INTO SALES_INFO VALUES(1,1000,800,400);
INSERT INTO SALES_INFO VALUES(2,800,600,400);
INSERT INTO SALES_INFO VALUES(3,800,NULL,400);
INSERT INTO SALES_INFO VALUES(4,NULL,600,400);
CREATE OR REPLACE PROCEDURE populate_sales_order AS
CURSOR get_sales_info IS
SELECT s_no,
           NVL(total_quantity,actual_quantity) total_quantity,
        packed_quantity
FROM   sales_info;
v_s_no          PLS_INTEGER := 0;
v_rem_qty     PLS_INTEGER := 0;
v_label_num   PLS_INTEGER := 1;
BEGIN
FOR rec IN get_sales_info LOOP
    v_rem_qty := rec.total_quantity + v_rem_qty;
    v_s_no    := rec.s_no;
     WHILE v_rem_qty >= rec.packed_quantity LOOP
       INSERT INTO sales_order( s_no, label, order_quantity)
       VALUES ( v_s_no, 'LABEL' || v_label_num, rec.packed_quantity );
       -- Reduce the packed qty from total qty and increment label counter
       v_rem_qty   := v_rem_qty - rec.packed_quantity ;
       v_label_num := v_label_num + 1;
     END LOOP;
END LOOP;
-- Put the last lot remaining qty into last carton
IF v_rem_qty > 0 THEN
INSERT INTO sales_order( s_no, label, order_quantity)
VALUES (v_s_no, 'LABEL' || v_label_num, v_rem_qty );
END IF;
COMMIT;
END;
S_NO    LABEL                                ORDER_QUANTITY
  1          LABEL1                                    400
  1          LABEL2                                    400
  2          LABEL3                                    400
  3          LABEL4                                    400
  3          LABEL5                                    400
  4          LABEL6                                    400
  4          LABEL7                                    400
{code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • Hello I am Matthew Alexander and I am having trouble with SEO for 2 websites. One of the websites has go daddy's SEO and one of them doesn't. I am currently using a mac. Is their anything I should do?

    @

    Hi,
    Sites' positions in our search results are determined based on hundreds of factors designed to provide end-users with helpful, accurate search results. some basic steps are
    1. Keyword research
    2. Content, make sure you have unique and original content. No Duplicate content
    3. Back link from quality sites, not from spam.
    and so on.
    I am adding some links from where you can begin, hope this helps
    See
    How Search Works by Google
    https://www.google.com/intl/en_us/insidesearch/howsearchworks/index.html
    For more information about improving your site's visibility in the Google search results, I recommend visiting Webmaster Academy which outlines core concepts for maintaining a Google-friendly website.
    Intro to Webmaster Academy - Webmaster Tools Help
    Please let me know if you have any other query.

  • Newbie having trouble with searching for apps.

    I'm an experienced an experienced Windows user, finding myself surprisingly lost on my new iPad and iTunes.
    (Surpising because, although I'm used to dealing with oddball and sometimes frustrating things on Windows,  I had heard the Mac and iPad interface fast simpler to navigate and more frustration free.)
    So please excuse what may seem like dumb newbie questions about what should be, and probably are to you experienced iTunes and iPad users, simple things:
    For starters:
    I'm search for a few apps in the app store that I know for sure exist and know the exact names:
    One is the
    iPad User Guide
    The other is
    the AOPA flight planner app.
    I know it exists because it's installed on my wife's iPad. Can't remember how I found it on her iPad.
    When I use the apps store search box (whether I do it in the app store in the iPad or in iTunes on my Windows 7 computer)
    I keep failing to find them.
    I've tried putting
                           iPad user guide
                            AOPA flight planner
      or even just                AOPA
    in the search box in both environments and clicking the search (magnifying glass) icon.
    I either get a mess of apps with  AOPA in the name (but not the one I want)
    or a message saying the equivalent of "sorry... not found." 
    What the heck am I doing wrong?
    All help appreciated.
    Alex

    You are not doing anything wrong. Those apps just do not appear to be available any more.
    They will always be available to your wife since she downloaded them and they are backed up in her iTunes Library (assuming she synced it with iTunes since downloading them) but it would appear that anyone else trying to find them will be unsuccessful.
    These are not dumb questions nor are they trivial concerns. The whole digital distribution method has many advantages, but you just ran into one of its drawbacks.
    "Ownership" of software was always a controversial subject, but the way things are going the argument will soon be a moot point... unfortunately.

  • Is there people who are having trouble with 4GLte for internet service?

    I signup for the service and I am sorry that I did ,it is so slow that I have regress back to when the internet started, the battery life is lousy it does not last
    very long. I should have stayed with Cable. Sales people are not very truthful.

    Hello manyhats,
    I would like to help you.  I will need to ask a series of questions to assist.  What type of device do you have?  Has the speed always been the same since you received your device or did this just begin?  What city, state and zip are you experiencing this in?  Does this happen every where you go or in a specific location?  How long is the battery lasting after a full charge?  Please respond to the previous questions so I may further understand and assist.  Thank you. 
    TominqueBo
    VZW Support
    Follow us on Twitter at @VZWSupport

  • Having trouble with playlist for days!!!! ggrrrrr!

    I've tried a lot fo things and no results...even bought PodUtil but still nothing works! when i hook up my ipod to my computer under "devices" I can see my ipod and if i click on it i can see all my songs and PLAYLISTS!! but I cant see the playlist in the actual Itunes! so if i disconnect it the playlist is gone...i want to import music and be able to add them to my playlist but there are not there! is there a ways i can transfer the playlist straight from my ipod to my itunes!??? i've tried export/import but nothing! any help will be good..thank you for your time!

    If you create a Playlist inside your iPod, that Playlist will only reside on your iPod - there is no straightforward way of getting that Playlist and its songs back to iTunes.
    If you're ever creating a Playlist that you want on your iPod and you might want on your iTunes too, it's best to create it inside the iTunes Library, then drag the Playlist onto your iPod. This way you'll have the Playlist on both your iPod and on iTunes.

  • Having trouble with installation for windows 7

    I downloaded flashplayer 10.3 for internet explorer 32bit and now it is completly not working. Are there any files licenses that I am missing? i have uninstalled it and done everything that i could to get it working again. What can I do to get it working again?

    Could you try the steps listed in this FAQ to see if they help?
    Enabling Flash Player in Internet Explorer 9
    Thanks,
    Chris

  • Having trouble with passowrd for router :(

    Hi,
    I have a Linksys router, model # BEFW11S4.  I do not have the software on my computer to create a password, therefore I used the linksys manual to figure out how to create a password using the internet.  I got to the correct place to create a name for my wifi and a password and did all the correct steps.  But when i type in a password, it does not save it and so i cannot make my network secure.  I do not want people using my wifi but I cannot seem to make a password for it.  Here are the directions i used:
    [   To access the web-based utility, launch Internet Explorer or Netscape Navigator, and enter the Router’s default IP
    address, 192.168.1.1, in the Address field. Then press Enter.
    A password request page will appear. (Users of other versions of Windows will see a similar screen.) Leave the
    User Name field blank. The first time you open the Web-Based Utility, use the default password admin. (You can
    set a new password from the Administration tab’s Management screen.) Then click the OK button.   ]
    Thank you.

    I think you need to be doing your adjustments through a page like this, instead of in your Internet Explorer browser.
    http://ui.linksys.com/files/BEFW11S4/v4/1.50.14/Setup.htm
    Go here
    http://homesupport.cisco.com/en-us/support/routers/BEFW11S4
    Click on DOWNLOADS and choose your model.
    There's a link to "Where's my model number?"
    Click that to read how to look for your model number and download the software that corresponds to your number.
    Then you should be able to get this project completed, once and for all.
    If anyone has any better ideas, or possibly even correcting my assumptions, please chime in.
    Hope this helps.
    Namaste <3

  • I am having trouble with iTunes for both my computers windows xp and 7.

    Both accounts are able to be logged in but I can't view anything on the itunes store. I have used the itunes loaded on xp before. The windows 7 itunes 'progress line' stops half way. On one occasion I saw a html text version of the itunes store but it wasn't functional. Any suggestions?

    Try this,
    Close your iTunes,
    Go to command Prompt -
    (Win 7/Vista) - START/ALL PROGRAMS/ACCESSORIES, right mouse click "Command Prompt", choose "Run as Administrator".
    (Win XP SP2 & above) - START/ALL PROGRAMS/ACCESSORIES/Command Prompt
    In the "Command Prompt" screen, type in
    netsh winsock reset
    Hit "ENTER" key
    Restart your computer.
    Now launch your iTunes and see if it is working now.

  • I have an Ipod Touch (4th Gen) and I am having troubles with my downloads from purchasing music from the Ipod. On my downloads icon in the Itunes Store (on Ipod) there is a symbol of how many songs I still have waiting to download, but they wont download.

    I have been having troubles with this for months and am extremly tired of not being able to download my songs. I bought these songs off of Itunes as well, so I really hope i can retrieve them. I do not know where to find a personal apple support person yet, does anyone know where to find one on the website?

    See these previous discussions:
    Waiting applications: Apple Support Communities
    Downloading apps stuck on waiting...: Apple Support Communities

  • Still having trouble with audio on Macbook Pro

    I had posted a discussion board earlier on this issue. I've been having trouble with audio for certain videos on youtube and basically any website embedded with a video. The audio works for a few seconds that doesn't or it doesn't work at all. My volume is up, not on mute, and the one on the video isn't on mute either. It's funny because I just tried watching a video on Firefox (as opposed to Safari) and it works. Could it possible be something with the settings for safari?

    Try restarting your Mac, resetting your router, and resetting your modem. My cable internet has gotten slow at times as well, and when I reset my router everything cleared up.

  • HT5085 having trouble with new phone activation

    Im having trouble with actavation for my sprintpcs device iphone5s

    Hi there Lilly015,
    You may find the troubleshooting steps in the article below helpful.
    iPhone: Troubleshooting activation issues
    http://support.apple.com/kb/ts3424
    -Griff W. 

  • Having trouble with email reviews

    Hi all, I am testing Acrobat X for my company and I am having trouble with testing for "send for email review/merge comments". In my last test I made a PDF from InDesing as usual and on my "test" Mac using Acrobat X I opened the PDf and sent it to 3 people for email review. One of the people was using a PC and Acrobat 9 Reader, the other two were using Acrobat X to make comments and send back. I should note that I am using one test machine (iMac) for all three of the Mac reviews, but each individual is logging on with their ID for the network and the email program (entourage).
    All three reviewers were able to get the PDF in the email, make comments and then use the "send comments" button to send back to me.
    My problem is that when I got all three emails back, and when I logged into the test machine as myself, opened the returned PDFs, I was only able to "merge comments" from one reviewer (from Mac) to my original PDF. With the email from the PC and one email from the iMac, I was UNABLE to merge these two sets of comments. The merge comments button was unavailable, I never got the message about if I wanted to "merge comments" or "No, open this copy only." And when I tried to go through "comments>merge comments onto master PDF" I was not able to see that option anywhere, either.
    Sorry for the long explanation, but I want to include as much info as possible to try to get the proper feedback from you all.
    Thanks in advance for any input you can provide.

    Just to be clear here, when you say that " I should note that I am using one test machine (iMac) for all three of the Mac reviews, but each individual is logging on with their ID for the network and the email program (entourage). " you mean that you have created 3 different users on your mac machine and configured entourage for each of them. If not then please explain this.
    Have you tried using any of these:
    a) 2-3 Mac partitions for the different users
    b) 2-3 different mac machines for the same
    c) maybe 2-3 Mac Virtual machines on a Mac main machine
    If it is possible can you please try that scenario on any of the above mentioned combinations and let us know the results. This will help us a lot in narrowing down the issue.
    Thanks,
    Abhilasha

  • Having trouble with garageband loops are out of time with other loops

    having trouble with garageband have bought loops from primeloops and beat loops are not in time when i paste other loops down for example certain loops do not lock into measure region correctly .. so say for instance i lay down my beat then i try to add hi hat below and the beat is not in time with hi hat any awnsers may have pressed some setting accidently because this hasn t happened before as previously using these loops were all in time and locked at correct measures ..

    The GarageBand experts await you here:
    https://discussions.apple.com/community/ilife/garageband

  • Hi, i am having trouble with my mac mail account, i cannot send or receive any emails because of the server connection problems. Message says it could not be connected to SMTP server. Thanks in advance for your help.

    Hi, i am having trouble with my mac mail account, i cannot send or receive any emails because of the server connection problems. Message says it could not be connected to SMTP server. Thanks in advance for your help.

    Hello Sue,
    I have an iPad 3, iPad Mini and iPhone 5S and they are all sluggish on capitalisation using shift keys. I hope that Apple will solve the problem because it is driving me crazy.
    I find using a Microsoft Surface and Windows 8 phone, which I also have, work as well as all the ios devices before the ios 7 upgrade.
    It has something to do with the length of time that you need to hold the shift key down. The shift key needs to be held longer than the letter key for the capitalisation to work. For some reason, this is a major change in the way we have learnt to touch type on computers. I am having to relearn how to type!
    Michael

  • I am having trouble with some of my links having images. For example, Foxfire has a picture that looks like a small world. The links in question are blank.

    I am having trouble with my links/websites having images attached to them. The place where the image should be is blank. For example, AARP has an A for its image. My storage website has a blank broken box where the image should be. I forgot I had trouble and had to reset Foxfire, this problem occurred after that reset.

    cor-el,
    Mixed content normally gives the world globe image, unless you are using a theme that uses a broken padlock instead. Maybe the gray triangle means invalid? I came across that in a few themes (what is invalid was not made clear), but those were not using triangle shapes to indicate that.
    I came across that mention in one of the pages you posted:
    * https://support.mozilla.org/kb/Site+Identity+Button
    I cannot attach a screenshot because I have not seen a triangle of any kind in my address bar.

Maybe you are looking for

  • Active Directory Connector Questions in 11.1.2.1

    Hello All.  I am new to this version of IDM and I am trying to get through the setup and config.  I just installed a single instance of 11.1.2.1 with OUD, OAM, OIM.  I installed the Active Directory connector for User Management and I believe I have

  • Anyone get message this iphone cannot be used because the applie mobile device service is not started?

    Plugged in my phone to sync and got this message "This iphone cannot be used because the Apple Mobile Device service is not started.  Does anyone know that I need to do?

  • Migration workbech's prerrequisites

    Hi forum members I want to install Oracle migration worbech on windows, but first I have to prepare all requirements, supposedly are these: *Olite database 5.0.2.0.0 --> Could work with Oracle Database Lite 10g Release 2 (10.2.0.1) for Microsoft Wind

  • Prompt on JVM shutdown

    I want to show a popup message to save changes when the user abruptly kills my swing application. Like if the user types ctrl+C in the dos window from which the swing application is launched or by clicking on the stop button in the JBuilder from wher

  • Export the EPMA "Import Results" as a file?

    The Log Console exports deployment logs as files but the "Import Results" of an import profile can only be viewed within EPMA. Is there a way to export these "Import Results" as a file?