Help needed in PL/SQL for updating the column for multiple records

Hi,
I am new to PL/SQL and need some help. What is the most effiecient way to update some field in a table as I may need to update thousands of records. I have a coulmn groupid can have multiple records tied to it. All the records attached to some groupid have a priority field also.
How can I update the prorityfield value for all the groupids in a profiecient way. Here is a sample data
GroupId     Priority
1            1
1            2
1            3
1            4
1            5
2            1
2            2
2            3
3            1Here I have three groups 1, 2, 3. Now if any group contains only one record the priority remains same e.g. groupid=3 on top. If any group contains more than one record e.g. groupid=1 & 2 I want to re-arrange the priority fields e.g. If I want to update groupid=1 now if I change the priority of 2 to 5 (make it the last) I want to rearrange the remaing records priority i.e. if 2 becomes 5 as I have 5 rows for groupid=1 then 5 becomes 4, 4 becomes 3, 3 becomes 2 and 1 remains the same.
Same wya if I want to make the priority 1 to 3 for groupid=2 then need 2 to become 1 and 3 to become 2 etc....
Any help is appreciated.
Thanks

Hi,
You don't need PL/SQL to do this (though you can put the following in PL/SQL if you want to):
UPDATE     table_x
SET     priority = CASE
               WHEN  groupid     = 1
               AND   priority = 2
                    THEN  5
               WHEN  groupod     = 1
               AND   priority     BETWEEN 3 AND 5
                    THEN  priority - 1
               WHEN  groupid = 2
               THEN
                    CASE
                         WHEN  prioity = 1
                         THEN  3
                         ELSE  priority - 1
                    END
             END
WHERE     groupId          IN (1, 2)
AND     (     priority     BETWEEN 2 AND 5
     OR     groupid          = 2
     );There are lots of different techniques that can reduce your coidng: for example, the nested CASE statement used for groupid=2 above.
You could do several smaller UPDATEs (for example, one just for groupid=1). Execution will be slower, but coding and testing will be faster.
You could make the "magic numbers" 2 (for groupid=1) and 1 (for groupid=2) variables, even outside of PL/SQL.
If you need more help, post the information that Satyaki requested.

Similar Messages

  • Looking for help to update the certificate for my Exchange Email Account...

    I'm trying to update the certificate for my Exchange Email Account...Dell had me delete the account, install the new certificate on my phone, and set up the email again...But it still won't work and acts like it can't find/use the new cert.  Any suggestions besides a hard resest of the phone?

    That's a great question, LSchmitz!
    Is the e-mail account on your cell phone? Which device? If its on your phone, an Exchange e-mail, may need to be provisioned/ set up by your employer/ IT department.
    VanessaS_VZW
    Follow us on Twitter @VZWSupport
    If my response answered your question please click the "Correct Answer" button under my response. This ensures others can benefit from our conversation. Thanks in advance for your help with this!!

  • HT1338 i have apps to be updated but when i try to update them a message pops out saying "You have updates for other accounts, please sigh in with the other id". Can some one help me how can i still update the same with the new apple id ive created.

    i have apps to be updated but when i try to update them a message pops out saying "You have updates for other accounts, please sigh in with the other id". Can some one help me how can i still update the same with the new apple id ive created. As i dont have the access to the earlier id anymore.

    You cannot. The apps are assigned to that Apple ID and there is nothing you can do to change that. You could choose to download them again with the new Apple ID, any paid apps will need to be purchased again.
    Hope that helps.

  • Have an ipod and then got the wife an iphone4. all passwords are screwed up. she can not access playstore cuz she doesn't have password. i can not get find any help on how to get or update a password for the ipod. and then get her a separate password for

    have an ipod and then got the wife an iphone4. all passwords are screwed up. she can not access playstore cuz she doesn't have password. i can not get find any help on how to get or update a password for the ipod. and then get her a separate password for her iphone. we need to save her photos, music, etc to ? icloud and the phone stuff to verizon cloud? so when she gets her new Iphone6 she can have all her "stuff" back on the new phone. hope this makes sense. please offer suggestions here or at [email protected] thanks for your help!

    Oh no! I'm sorry to see there's a lot of confusion here and data shared, x-rayDon. We can definitely work to fix. This happens when two devices share the same Apple ID, so she will need to reset hers. She can do so by assessing this link Apple - My Apple ID. You will need to decide who will keep the account if want separate Apple IDs since purchases cannot be shared unless you do Family Sharing.
    RobinD_VZW
    Follow us on twitter @VZWSupport

  • Need a PLSQL API for update the oe_order_headers_all table

    Hi all,
    I need a PLSQL API for update the oe_order_headers_all table.
    Anyone know please help me.
    Regards,
    M.Soundrapandian.

    Use the Process Order API to update this table.
    Note: 746787.1 - Process Order API In Order Management
    https://metalink2.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=746787.1
    Oracle Order Management Open Interfaces, API, & Electronic Messaging Guide
    http://download-uk.oracle.com/docs/cd/B25516_14/current/acrobat/115omapi.zip
    Oracle Integration Repository
    http://irep.oracle.com

  • HT5654 Im clicking help and checking for updates, the updates come up so I click to download it and nothing happens, help me?

    Ive clicked on help to check for updates, the update I needed came up so I clicked update and nothing happened, what do I do?

    Going by your profile your Mac has v10.5.8 installed. That is the most recent version available for Leopard.
    You may be able to upgrade to v10.6 Snow Leopard >  Mac OS X v10.6 Snow Leopard - Technical Specifications
    Snow Leopard is available for purchase from the Apple online store > Mac OS X 10.6 Snow Leopard - Apple Store (U.S.)
    With Snow Leopard installed, iTunes would be updated for you.

  • Trying to update the software for my iphone and it keeps saying download has been corrupted. an same for imac update. help?

    trying to update the software for my iphone and it keeps saying download has been corrupted. an same for imac update. help?

    Hi NWL1,
    Thanks for the question. If I understand correctly, the iPhone won't update and is stuck. I would recommend that you read this article, it may be able to help you resolve or isolate the issue.
    If you can't update or restore your iPhone, iPad, or iPod touch - Apple Support
    Thanks for using Apple Support Communities.
    Have a great day,
    Mario

  • Why can't i update the ios for my ipod? I'm stuck at 3.1.3. Please help.

    Why can't i update the ios for my ipod? I'm stuck at 3.1.3. Please help.
    I have itunes updated but it doesn't show that an update is available for the ipod.

    Probably because yu have a 1G iPod that can only go as high as 3.1.3. To identify your iPod:
    Identifying iPod models
    If you have a later iPod, what version of iTunes do you have on your computer and what computer OS and version?

  • I am afraid for updating the os of my iphone4s to 7.0.3. right now i m on 7.0.2 need advice do i update or not ?????

    I am afraid for updating the os of my iphone4s to 7.0.3. right now i m on 7.0.2 need advice do i update or not ?????

    Why would you not update? iOS 7.0.3 is mostly bug fixes. Read here:
    http://support.apple.com/kb/DL1691

  • I tried to update the software for my iPhone 4S. It froze, and now won't turn off, or on, or sync.  Any ideas on how to fix this?

    I tried to update the software for my iPhone 4S, 16 GB to the most recent version (8.1?).  I don't know what I was updating from, because I can't access that, but it was whatever was installed on it (I got it about a year ago, so probably 6.something). 
    It froze, and now won't turn off, or on, or sync with my macbook plus, which is what I have always sync'd it to.  (I backed it up and sync'd it right before I tried to update the software.)
    Since it originally froze almost 3 hours ago, it shows a white screen with the apple on it and a line underneath.  When I try to sync with my laptop, it says it needs me to enter a passcode on the phone, which I can't enter because the screen is frozen.  So I'm unable to access the iPhone portion of iTunes.
    I have tried to turn it off, with no luck.  I have tried rebooting my laptop and syncing, but I still get the same result.
    Does anyone know how to fix this?
    I really wanted to wait to update the software, but I was having internet connectivity issues for the past 3 weeks, and Sprint suggested updating the phone's software.
    Thanks in advance for your help!

    Hi NWL1,
    Thanks for the question. If I understand correctly, the iPhone won't update and is stuck. I would recommend that you read this article, it may be able to help you resolve or isolate the issue.
    If you can't update or restore your iPhone, iPad, or iPod touch - Apple Support
    Thanks for using Apple Support Communities.
    Have a great day,
    Mario

  • HT1483 I get a message "The Itunes server could not be contacted, check your internet connection" when trying to check for Ipod Nano software updates. I have a 1st generation Nano and haven't updated the software for a while. My internet connection is wor

    I get a message "The Itunes server could not be contacted, check your internet connection" when trying to check for Ipod Nano software updates. I have a 1st generation Nano and haven't updated the software for a while. My internet connection is working. Was thre a change in the internet address for NANO software updates? Do I have to reconfigure something in Itunes to point to the correct address?

    What version of iTunes are you using?  The latest is 10.6.3. In iTunes, choose Help -> About iTunes to check the version number. If it's lower than 10.6.3, download the latest version from here.
    B-rock

  • Good morning a few weeks ago  I send the request for the replacement program of my ipod nano 1st generation and they sent me the shipping box but I did not get the label to go back,  and I can not  return it , i need to you sent me again the box for retu

    Good morning a few weeks ago  I send the request for the replacement program of my ipod nano 1st generation and they sent me the shipping box but I did not get the label to go back,  and I can not  return it , i need to you sent me again the box for return the ipod

    Best thing would be to call Apple up again, and let them what has happened and they'll help you!

  • Creation of function module for updating the ztable

    Hi,
    I am sending the requirement for ceation of function module for updating the ztable.
    Requirement----
    Table Updation rule (New record)
    While creating a new record the calling function will export the following to the table handling function.
    Table field     Probable Values
    ZORDERNO------->     Sales Delivery no in case of sales orderShipment no in case of transfer order
    UNAME----
    >     User ID
    ZORDTYPE----
    >     SALEOR in case of sales orderTRANSF in case of transfer order
    ZREFDOCNO----
    >Sales Order no in case of sales orderPurchase Order no in case of transfer order
    ZREFDOCNO1----
    >Delivery no in case of transfer order
    The table handling function will calculate the following fields
    Table field     Probable Values
    ZREQNO----
    >Running serial number (incremented by 1 for each new record)
    ZREQDAT     -
    >System date
    ZREQTIME----
    >     System time
    ZSTATUS----
    >OPEN (for all new records)
    Before inserting a new record the table handling function will always check if a previous record exists for the same order / shipment no. if record exists the function will not insert a new record.
    Table Updation rule (Status Update)
    While updating a record the calling function will export the following to the table handling function.
    Table field     Probable Values
    ZORDERNO----
    >Sales order no in case of sales orderShipment no in case of transfer order
    ZSTATUS----
    >CANCEL if cancellation successfulERROR if cancellation not possible (order already processed)
    The table handling function will calculate the following fields
    Table field     Probable Values
    ZSTATDAT----
    >System date
    ZSTATTIME----
    >     System time

    Do you have to create/update new record in Ztable through Function Module ?
    or you need to write FM only for validation?
    Any how, you need to create a Program with Input values for the fields of Ztable, and for rest of fields the Value can be calculated based on input as per your requirement.
    Let me know clearly what exactly u need ?
    Regards,
    Kiran

  • How to update the path for a field which is of type textarea

    Hi,
    1.I have multiple record block,i need to update the textarea field in this multi entry block.I have put a for loop to achieve the same,however i'm able to update the path for text field,checkbox,selecttype,but am unable to update the path for field which is of textarea.Please suggest.
    2. Also i have another problem which occurs randomly.although i have record for a button click event in  my property file,button click is not happening during the playback.am getting error asVariable "obj.libraryname.web_button_BTN_1" not found for string:
    please not i have entry for the above button in my property file.
    Please suggest.

    Say i have 5 rows then
    for(int i=1;i<=5;i++){
    String Newpath = updatepath(eval("{{obj.libraryname.web_input_text_fieldname}}"),i)
    web.text_area(Newpath).setText("Text to be set")
    Below function is used to update my path
    public String updatepath(String path,int i) throws exception {
    String FPath = "";
    if(i<2) {
    FPath = path.substring(0, path.indexOf("'", path.lastIndexOf("@id=")+5))+path.substring(path.indexOf("'", path.lastIndexOf("@id=")+5));
    } else {
    FPath = path.substring(0, path.indexOf("'", path.lastIndexOf("@id=")+5))+(i-1)+path.substring(path.indexOf("'", path.lastIndexOf("@id=")+5));
    return Fpath
    anyother way to update path and set the fields in mutiple block is appreciable
    thanks
    Suresh

  • Having trouble updating the plugin for camera raw on photoshop CS2

    I am having trouble updating the plugin for the camera raw on photo shop CS2. I downloaded the plugin and put it where the instructions told me but I still couldnt open raw photos. any help would be great

    Use the DNG converter for the latest camera support in CS2:
    Why doesn’t my version of Photoshop or Lightroom support my camera?: http://adobe.ly/ACRandDNG

Maybe you are looking for