Need help on the update statement

Hi,
I have a small requirement. I have a table called test1 and it has 2 columns, nam and seq. nam is a VARCHAR2(100) and seq is a NUMBER.
In the seq I have values like, 2, 3, 7, 9, 25. I would like to update the seq value in an order such that it will be modifed like, 1, 2, 3, 4 and 5.
Here is the scripts, I have used.
CREATE TABLE test1
(nam VARCHAR2(100),
  seq NUMBER);
INSERT INTO test1 VALUES('AAA', 2);
INSERT INTO test1 VALUES('BBB', 3);
INSERT INTO test1 VALUES('CCC', 7);
INSERT INTO test1 VALUES('DDD', 9);
INSERT INTO test1 VALUES('EEE', 25);
COMMIT;
And, I would like to achive this in a simple single DML statement. (The required output would be something like, AAA - 1, BBB - 2 etc,...)
I have tried the following query. It is working fine. But If I have a better solution to it, I would to implement the same.
UPDATE test1 a
  SET seq =
  (SELECT rn
  FROM (SELECT ROW_NUMBER() OVER(ORDER BY seq) rn FROM test1) x
  WHERE a.rowid = x.rowid);
PS: I am using Oracle 11.2.0.2.0 (11g)
Thanks In Advance!
With Regards,
VST

SQL> CREATE TABLE test1 
  2   (nam VARCHAR2(100), 
  3    seq NUMBER); 
Table created.
SQL>  INSERT INTO test1 VALUES('AAA', 2); 
1 row created.
SQL>  INSERT INTO test1 VALUES('BBB', 3); 
1 row created.
SQL>  INSERT INTO test1 VALUES('CCC', 7); 
1 row created.
SQL>  INSERT INTO test1 VALUES('DDD', 9); 
1 row created.
SQL>  INSERT INTO test1 VALUES('EEE', 25); 
1 row created.
SQL>  COMMIT; 
Commit complete.
SQL> select * from test1;
NAM                                                                                                         SEQ
AAA                                                                                                           2
BBB                                                                                                           3
CCC                                                                                                           7
DDD                                                                                                           9
EEE                                                                                                          25
5 rows selected.
SQL> update test1 set seq = rownum;
5 rows updated.
SQL> select * from test1;
NAM                                                                                                         SEQ
AAA                                                                                                           1
BBB                                                                                                           2
CCC                                                                                                           3
DDD                                                                                                           4
EEE                                                                                                           5
5 rows selected.

Similar Messages

  • Need help with the session state value items.

    I need help with the session state value items.
    Trigger is created (on After delete, insert action) on table A.
    When insert in table B at least one row, then trigger update value to 'Y'
    in table A.
    When delete all rows from a table B,, then trigger update value to 'N'
    in table A.
    In detail report changes are visible, but the trigger replacement value is not set in session value.
    How can I implement this?

    You'll have to create a process which runs after your database update process that does a query and loads the result into your page item.
    For example
    SELECT YN_COLUMN
    FROM My_TABLE
    INTO My_Page_Item
    WHERE Key_value = My_Page_Item_Holding_Key_ValueThe DML process will only return key values after updating, such as an ID primary key updated by a sequence in a trigger.
    If the value is showing in a report, make sure the report refreshes on reload of the page.
    Edited by: Bob37 on Dec 6, 2011 10:36 AM

  • Need help with the update queries - joining three tables -

    We have three tables shown below, each with millions of rows;
    And need some updates in here;
    T_CHECK->TOTAL_AMT_PAID should be equal to
    aim00.t_chck_clm_xref->amt_paid + aim01.t_chck_clm_xref->amt_paid;
    Some CHECK_SAK values exist in aim00.t_chck_clm_xref and some exist in aim01.t_chck_clm_xref;
    We tried to update using the queries within PL/SQL shown below:
    Is there a way to make these more effecient?
    SQL> desc aim.t_check;
    Name Null? Type
    CHECK_SAK NOT NULL NUMBER(9)
    TOTAL_AMT_PAID NOT NULL NUMBER(11,2)
    DTE_ISSUE NOT NULL NUMBER(8)
    SQL> desc aim00.t_chck_clm_xref
    Name Null? Type
    CHECK_SAK NOT NULL NUMBER(9)
    AMT_PAID NOT NULL NUMBER(10,2)
    SQL> desc aim01.t_chck_clm_xref
    Name Null? Type
    CHECK_SAK NOT NULL NUMBER(9)
    AMT_PAID NOT NULL NUMBER(10,2)
    create or replace PROCEDURE CHECKSUPDATE IS
    cursor my_cursor is
    select /*+ DRIVING_SITE(t_check) INDEX(t_check) */
    tot, mid, aim.t_check.total_amt_paid from
    (select sum(aim01.t_chck_clm_xref.amt_paid) tot,
    aim01.t_chck_clm_xref.check_sak mid from aim01.t_chck_clm_xref
    where
    not exists (select 'x' from aim00.t_chck_clm_xref
    where aim01.t_chck_clm_xref.check_sak = aim00.t_chck_clm_xref.check_sak
    group by aim01.t_chck_clm_xref.check_sak) TABLE1, aim.t_check
    where aim.t_check.check_sak = table1.mid
    and aim.t_check.total_amt_paid <> tot;
    my_count NUMBER;
    BEGIN
    my_count:=0;
    for my_pos in my_cursor loop
    update aim.t_check a set total_amt_paid=my_pos.tot
    where a.check_sak=my_pos.mid;
    my_count:=my_count+1;
    if (mod(my_count,1000)=0) THEN
    commit;
    end if;
    end loop;
    commit;
    END CHECKSUPDATE;

    >
    SQL> desc t_check;
    Name Null? Type
    CHECK_SAK           NUMBER(9)
    TOTAL_AMT_PAID NUMBER(11,2)
    DTE_ISSUE NUMBER(8)
    SQL> desc t_chck_clm_xref
    Name Null? Type
    CHECK_SAK      NUMBER(9)
    AMT_PAID NUMBER(10,2)
    SQL> desc t_test
    Name Null? Type
    CHECK_SAK NUMBER(9)
    AMT_PAID NUMBER(10,2)
    select check_sak, sum(amt_paid)
    from (
      select check_sak, amt_paid from t_chck_clm_xref
      union all
      select check_sak, amt_paid from t_test
    group by check_sak;and use this query in an UPDATE statement or a MERGE statement, as Tubby suggested, against the T_CHECK table.
    isotope

  • Need help for the sql statement !!!!!

    hi all,
    i need a sql statement for a query, how can i get the result from the rownum between 100 and 150?
    plz help

    use a scrollable statement:
    PreparedStatement stat = Connection.prepareStement("select * from blah", ResultSet.TYPE_SCROLL_INSENSITIVE,
    ResultSet.CONCUR_UPDATABLE);
    ResultSet rs = stat.executeQuery();
    rs.absolute(100);
    while (rs.next()) {
    String something = rs.get(1);
    Look into the JDK API reference for ResultSet to get an expalantion of scrollable statements.

  • I need help! I updated the new 6.1.3 last night. Since that time my phone will not charge. The phone is plugged in and shows as charging but the battery still drains. What can I do? I need help!

    I need help! I updated the new 6.1.3 last night. Since that time my phone will not charge. The phone is plugged in and shows as charging but the battery still drains. What can I do? I need help!

    Restore iPhone with iTunes on your computer.

  • New update on my iTunes 8.2 computer. Sync my iPads on the computer missing playlist on my computer ??? Need help. Worst update ever   

    new update on my iTunes 8.2 computer. Sync my iPads on the computer missing playlist on my computer ??? Need help. Worst update ever   

    Hello there, dancingteacher.
    Removing and re-installing iTunes can be a challenging endeavor and has to be done in a very particular way. The following Knowledge Base article provides a clear, step-by-step process of removing iTunes:
    Issues installing iTunes or QuickTime for Windows
    http://support.apple.com/kb/ht1926
    The "Additional Troubleshooting" section also includes a link to updates and conflicts with software for your Windows Operating System as well.
    Thanks for reaching out to Apple Support Communities.
    Cheers,
    Pedro.

  • HT6114 hello .. i am using mavericks OS  and it is showing it needs updates about 800 meg. and every time i download that it dosent do anything and again it is beginig to download again and again that.. please help me. the update is 10.9.2

    hello .. i am using mavericks OS  and it is showing it needs updates about 800 meg. and every time i download that it dosent do anything and again it is beginig to download again and again that.. please help me. the update is 10.9.2

    To answer the post title FireFox save all downloads automatically in the download folder, which you can find in the Documents folder. If you want to choose where to save your downloads go to tools>options>check always ask me where to save files.
    Secondly, I am assuming you have IE 8 installed as this is the only version that supports this fix that is currently not in beta. Go to control panel>internet options>advanced tab and reset the settings at the bottom. This may or may not fix the problem but it is a good first step.

  • I need help restoring the ability to view Youtube and all videos of my 4 year old MacBook after receiviving a meaage the the Adobe ineeds to be updated?  Thanks.ng

    I need help restoring the ability to view Youtube and all videos of my 4 year old MacBook after receiving a message the the Adobe ineeds to be updated?  Thanks.

    Did you upgrade whatever product from Adobe was out of date yet?

  • HT1199 need help installing the os x mountain lion update

    need help installing the os x mountain lion software update

    By default, ML no longer comes with the Java runtime preinstalled. I believe the route to enabling Java if you are going to need it is to run the Java Preferences app found in Utilities. It will inform you of Java's absence and offer to install the latest version and activate it. On subsequent runs, the Preferences app will allow you to fine tune how the runtime operates.
    Note that the new default operation is for the applet plugin to be disabled. You need to enable it as needed and it self-deactivates if unused in awhile. Also important to note that Java comes in both 32 and 64 bit versions and you can set the preferred order. Default is 64-bit but I've had issues with some applets failing to run and have had to switch the order.

  • Help with this update statement..

    Hi everyone,
    I am trying to update a column in a table .I need to update that column
    with a function that takes patient_nbr and type_x column values as a parameter.
    That table has almost "300,000" records. It is taking long time to complete
    almost 60 min to 90 min.
    Is it usual to take that much time to update that many records?
    I dont know why it is taking this much time.Please help with this update statement.
    select get_partner_id(SUBSTR(patient_nbr,1,9),type_x) partner_id from test_load;
    (it is just taking 20 - 30 sec)
    I am sure that it is not the problem with my function.
    I tried the following update and merge statements .Please correct me if i am wrong
    in the syntax and give me some suggestions how can i make the update statement fast.
    update test_load set partner_id = get_partner_id(SUBSTR(patient_nbr,1,9),type_x);
    merge into test_load a
    using (select patient_nbr,type_x from test_load) b
    on (a.patient_nbr = b.patient_nbr)
    when matched
    then
    update
    set a.partner_id = get_partner_id(SUBSTR(b.patient_nbr,1,9),b.type_x);
    there is a index on patient_nbr column
    and the statistics are gathered on this table.

    Hi Justin,
    As requested here are the explain plans for my update statements.Please correct if i am doing anything wrong.
    update test_load set partner_id = get_partner_id(SUBSTR(patient_nbr,1,9),type_x);
    "PLAN_TABLE_OUTPUT"
    "Plan hash value: 3793814442"
    "| Id  | Operation          | Name             | Rows  | Bytes | Cost (%CPU)| Time     |"
    "|   0 | UPDATE STATEMENT   |                  |   274K|  4552K|  1488   (1)| 00:00:18 |"
    "|   1 |  UPDATE            |        TEST_LOAD |       |       |            |          |"
    "|   2 |   TABLE ACCESS FULL|        TEST_LOAD |   274K|  4552K|  1488   (1)| 00:00:18 |"
    merge into test_load a
    using (select patient_nbr,type_x from test_load) b
    on (a.patient_nbr = b.patient_nbr)
    when matched
    then
    update
    set a.partner_id = get_partner_id(SUBSTR(b.patient_nbr,1,9),b.type_x);
    "PLAN_TABLE_OUTPUT"
    "Plan hash value: 1188928691"
    "| Id  | Operation            | Name             | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |"
    "|   0 | MERGE STATEMENT      |                  |   274K|  3213K|       |  6660   (1)| 00:01:20 |"
    "|   1 |  MERGE               |        TEST_LOAD |       |       |       |            |          |"
    "|   2 |   VIEW               |                  |       |       |       |            |          |"
    "|*  3 |    HASH JOIN         |                  |   274K|    43M|  7232K|  6660   (1)| 00:01:20 |"
    "|   4 |     TABLE ACCESS FULL|        TEST_LOAD |   274K|  4017K|       |  1482   (1)| 00:00:18 |"
    "|   5 |     TABLE ACCESS FULL|        TEST_LOAD |   274K|    40M|       |  1496   (2)| 00:00:18 |"
    "Predicate Information (identified by operation id):"
    "   3 - access("A"."patient_nbr"="patient_nbr")"Please give some suggestions..
    what's the best approach for doing the updates for huge tables?
    Thanks

  • I just created an iCloud email and I want to use that email for my iTunes account as well. I need help suiting the old apple I'd because I do not remember anything associated with that email and I don't know the security questions

    I just created an iCloud email and I want to use that email for my iTunes account as well. I need help switching the old apple ID because I do not remember anything associated with that email and I don't know the security questions or the login for that old email.

    You cannot do that.  The AppleID you used to create the iCloud account is an active primary email address.  The email address you created with the iCloud account is also an active primary email address (all Apple domain email address automatically become AppleIDs as well).  You cannot replace the primary email address on one active AppleID with the primary email address on another, active AppleID.
    You can use your iCloud email/AppleID with iTunes, but it will be a separate account, so all your previous purchases remain tied to the other AppleID you have.
    I don't understand your statement that you could not remeber your old AppleID password, as you would have had to use it to create the iCloud account in the first place (the first step of creating the iCloud account required you to login with your existing AppleID and password)?

  • Need help accessing the router web page.  I have been tol...

    Need help accessing the router web page.  I have been told my router is acting like a switch and the IP address is not in the proper range.  I have tried reseting the router (hold for 30 sec and unplug for 5 mins).  Didn't work.
    thanks

    What router are you using?  Almost all Linksys routers use 192.168.1.1 as the default local IP address, but there is at least one that uses 192.168.16.1 , namely the WTR54GS  (not the WRT54GS).
    You need to try again to reset the router to factory defaults.
    To reset your router to factory defaults, use the following procedure:
    1) Power down all computers, the router, and the modem, and unplug them from the wall.
    2) Disconnect all wires from the router.
    3) Power up the router and allow it to fully boot (1-2 minutes).
    4) Press and hold the reset button for 30 seconds, then release it, then let the router reset and reboot (2-3 minutes).
    5) Power down the router.
    6) Connect one computer by wire to port 1 on the router (NOT to the internet port).
    7) Power up the router and allow it to fully boot (1-2 minutes).
    8) Power up the computer (if the computer has a wireless card, make sure it is off).
    9) Try to ping the router. To do this, click the "Start" button > All Programs > Accessories > Command Prompt. A black DOS box will appear. Enter the following: "ping 192.168.1.1" (no quotes), and hit the Enter key. You will see 3 or 4 lines that start either with "Reply from ... " or "Request timed out." If you see "Reply from ...", your computer has found your router.
    10) Open your browser and point it to 192.168.1.1. This will take you to your router's login page. Leave the user name blank (note: a few Linksys routers have a default user name of "admin" (with no quotes)), and in the password field, enter "admin" (with no quotes). This will take you to your router setup page. Note the version number of your firmware (usually listed near upper right corner of screen). Exit your browser.
    If you get this far without problems, try the setup disk (or setup the router manually, if you prefer), and see if you can get your router setup and working.
    If you cannot get "Reply from ..." in step 9 above, your router is dead.
    If you get a reply in step 9, but cannot complete step 10, then either your router is dead or the firmware is corrupt. In this case, use the Linksys tftp.exe program to try to reload your router with the latest firmware. After reloading the firmware, repeat the above procedure starting with step 1.
    If you need additional help, please state your ISP, the make and model of your modem, your router's firmware version, and the results of steps 9 and 10. Also, if you get any error messages, copy them exactly and report back.
    Please let me know how things turn out for you.
    Message Edited by toomanydonuts on 01-21-2008 04:40 AM

  • When the update statement will check the constraint violation ?

    Hello all,
    i am working on data masking of production data using oracle Translate function.i have created a function otis_mask using translate function to mask sensitive values .For this i am tesitng on a small table. i have created a table with single primary key column SSN.
    sql>desc SSN_MASK
    Name Null? Type
    SSN NOT NULL NUMBER(10)
    1) i have inserted the value 9949577766. if resulted mask value exist in table it should throw the constraint violation error.But it is not throwing any error.rows are properly updating .
    Eg:-
    Table contains below values.
    PA_DATA_SUB @qdsrih30 >select *from SSN_MASK;
    SSN
    7727399911
    9949577766
    9989477700
    UPDATE SSN_MASK SET SSN=otis_mask(SSN);
    if above update statement process 7727399911 first then resulted mask value is 9989477700.This value is already in the table.
    if the update statement process 9949577766 first then resulted mask value is 7727399911.This value is already in the table.
    in any of the above scenario update statement should have to throw constraint violation error. But its not happening. rows are properly updating . when the update statement checking the constraint violation ? after processing all the rows or processing of each row ?
    Please help me in understandding the update statement processing ?
    Thanks,
    Venkat Vadlamudi.

    1)created a function as below.
    CREATE OR REPLACE Function otis_mask(incol varchar2) return varchar2 is
    random_str varchar2(20);
    begin
    select (translate(incol,'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890','qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0842319576')) INTO random_str FROM DUAL;
    return random_str;
    end;
    2. create a table ssn_mask.
    create table ssn_mask(ssn number(10) primary key);
    3) inserted 3 rows as below.
    insert into ssn_mask values(9949577766);
    insert into ssn_mask values(7727399911);
    insert into ssn_mask values(9989477700);
    4)UPDATE SSN_MASK SET SSN=otis_mask(SSN);
    5) Table contains below rows.
    Sql >select *from SSN_MASK;
    SSN
    9949577766
    7727399911
    9989477700.
    6)UPDATE SSN_MASK SET SSN=otis_mask(SSN);
    If the above statement process first row 9949577766,then otis_mask function will return 7727399911 and update statement will update the value of 9949577766 to 7727399911 .At this case 7727399911 is already in the table.So update statement should have to throw primary key constraint violation error.
    If the above statement process second row 7727399911 first ,then otis_mask function will return 9989477700.and update statement will update the value of 7727399911 to 9989477700.At this case 9989477700 is already in the table.So update statement should have to throw primary key constraint violation error.
    But its not throwing any integrity constraint violation error.
    i just want to know when update statement will check the constraint ?
    is update statement will first process all records and kepp in handy the new values then update the table with new values (or) process the first row and update the new value with old value then process second row and update with new value so on ?
    Thanks,
    Venkat Vadlamudi.

  • Need help about the SHA Message Digest ? & what is use of Message Diagest ?

    need help about the SHA Message Digest ? & what is use of Message Diagest ?
    1>i have one program of making message digest
    2>which requires two files name
    3>one for input like txt
    4> second is out put file of message digest
    can any one tell what is the use of second generated file .

    MessageDigest md = MessageDigest.getInstance("SHA");
    FileInputStream fis = new FileInputStream(args[0]);
    byte[] b = new byte[1024];
    int readed = -1;
    while((readed = fis.read(b)) > 0)
         md.update(b, 0, readed);
    fis.close();
    FileOutputStream fos = new FileOutputStream(args[1]);
    byte[] d = md.digest();
    StringBuffer sb = new StringBuffer();
    for(int i = 0; i < d.length; i++) {
         String str = Integer.toHexString(d[i] & 0xff);
         sb.append(str.length() < 2 ? "0" + str : str);
    fos.write(sb.toString().getBytes());
    fos.close();

  • How can I get my safari 5.1.10 to download the java update so I won't continue to get notices that my browser is out of date and I need to download the update, which then won't download.  Cannot view anything in youtube or most other places.

    Jeez.  Trying to view items in youtube.  I keep getting a blacked out picture telling me my browser is out of date and I need to download the update.  I do that and then it doesn't connect so I'm back at square one. 

    Hi MiMattheMac, you probably won't have any problems but just be aware upgrading from Snow Leopard to anything later is a big leap. Old, PowerPC - only programs won't work, for example, and even more recently developed programs won't work if their developers have not been updating them for recent OS X versions.
    If you haven't made a backup of your Mac yet, and you consider the information on it important, please consider doing that. It is the only practicable way to "undo" an OS X upgrade should you want to. Merely having a backup seems to preclude the need to ever use it.
    If the information on your Mac is not important to you, upgrading to Mavericks is even easier since you can completely erase the Mac first.
    In any event let the download complete.
    If this raises any concerns about installing it, and you need to ask questions to alleviate those concerns, you can just close this window when it eventually appears:
    The 5 GB downloaded file will not be deleted and will remain available until you actually install Mavericks. You can do that at any time convenient for you.

Maybe you are looking for