Update field table to the base sequence number another field

Hello

I have the following structure:

create the table from_list
*(*
NR_ID NUMBER of non-null,
EX_ID NUMBER of non-null,
NUMBER OF OE_ID
*);*

insert into from_list (NR_ID, EX_ID, OE_ID)
Select 1, 1, null of union double
Select 1, 1, 1 double Union
Select 1, 2, 3 double Union
Select 1, 2, 4 double Union
Select option 1, 2, null of union double
Select 2, 1, null of union double
Select 2, 1, null of union double
Select 3, 10, double null.

commit;

Thus,.

Select go t from_list
order of t.nr_id, t.ex_id, t.oe_id


NR_ID EX_ID OE_ID
1-1-1
1 1
1 2 3
1 2 4
1 2
2 1
3 10

I need to change the field value OE_ID null records and for each NR_ID, the EX_ID and the next OE_ID.

With the above data, the result would be:

NR_ID EX_ID OE_ID
1-1-1
1 1 2
1 2 3
1 2 4
1 2 5
2-1-1
3-10-1

Thank you.

The only thing I will add to the post of Warren is an additional sorting or two.

The collation that is used with the ROW_NUMBER function is not deterministic: in other words, he does not want to break all the possible links. In his case, the code worked, but, when you do not use a deterministic sort, then you let the tierbreaking randomly. There is never a guarantee that Oracle will sort it the same way every time.

Thus the ORDER BY in the analytical ROW_NUMBER() function must reference all three columns.

Here's how you need to change line 3 since its first solution:

ROW_NUMBER() OVER (PARTITION BY nr_id ORDER BY nr_id, ex_id, oe_id) oe_id

In the second solution, change fit in line 4

Tags: Database

Similar Questions

  • several insert using the same sequence number,

    Hello

    I need to use the same sequence number in several documents (insertion).

    Is this possible and how?

    Thank you

    It depends on how you are doing multiple inserts.  If you then run a bunch of single inserts something like:

    dev1 > create table t (ID, descr varchar2 (10));

    Table created.

    dev1 > create sequence t_seq;

    Order of creation.

    dev1 > select double t_seq.nextval;

    NEXTVAL

    ----------

    1

    dev1 > insert into values t (t_seq.currval, 'Rec 1');

    1 line of creation.

    dev1 > insert into values t (t_seq.currval, "Rec 2");

    1 line of creation.

    dev1 > insert into values t (t_seq.currval, 'Rec 3');

    1 line of creation.

    dev1 > insert into values t (t_seq.currval, 'Rec 4');

    1 line of creation.

    dev1 > insert into values t (t_seq.currval, 'Rec 5');

    1 line of creation.

    dev1 > select * from t;

    ID DESCR

    ---------- ----------

    1 rec 1

    1 rec 2

    1 rec 3

    REC 2 4

    REC 2 5

    You can use a similar approach, if you select data from another table as long as you can make the selection sufficiently selective to retrieve only the lines you need.

    John

  • Update a table using the clause

    Hello

    I want to update a table using the selected values.

    Cases in the sample:


    create table as empsalary)

    Select 1 as empid, 0 in the wages of all the double union

    Select option 2, the double 0);

    Data update are as follows

    with saldata as

    (

    Select 1 as empid, 5000 as wages, 500 as double pf

    Union of all the

    Select option 2, 10000,1000 like double pf

    )

    Select empid, salary saldata

    I tried the following query but does not work

    updated set of empsalary table (empid, salary) =

    (

    Select * from)

    with saldata as

    (

    Select 1 as empid, salary, 500 5000 as pf Union double all the

    Select option 2, 10000,1000 like double pf

    )

    Select empid, salary saldata

    ) sl

    where sl.empid = empsalary.empid

    )

    I use oracle 10g.

    Help, please.

    Krishna Devi wrote:

    Hello

    I want to update a table using the selected values.

    Cases in the sample:

    create table as empsalary)

    Select 1 as empid, 0 in the wages of all the double union

    Select option 2, the double 0);

    Data update are as follows

    with saldata as

    (

    Select 1 as empid, 5000 as wages, 500 as double pf

    Union of all the

    Select option 2, 10000,1000 like double pf

    )

    Select empid, salary saldata

    I tried the following query but does not work

    updated set of empsalary table (empid, salary) =

    (

    Select * from)

    with saldata as

    (

    Select 1 as empid, salary, 500 5000 as pf Union double all the

    Select option 2, 10000,1000 like double pf

    )

    Select empid, salary saldata

    ) sl

    where sl.empid = empsalary.empid

    )

    I use oracle 10g.

    Help, please.

    Thanks for posting creates table and test data.

    The error message would have helped because it's pretty obvious that this is the problem:

    Update table empsalary

    *

    ERROR on line 1:

    ORA-00903: invalid table name

    Just remove the word "table".

  • How to get the max sequence number when some record exists in the database table

    Hello

    I need to create the sequence that he should leave value max already exists in the table.

    Example:
    I have a table as below:

    ID NAME
    1A
    1 a
    3 C
    4 D


    Now, during the creation of sequence it should start from 5 but I should ' t START WITH 5 hard-code in the sequence to create. Is it possible to do without Hardcoding the max value in the sequence. It automatically brings the value max + 1 for the next data when I insert.


    CREATE THE TEST_SEQ SEQUENCE. NEXTVAL
    START WITH [Max + 1 val of the table]
    MAXVALUE 9999999999999999999999999999
    MINVALUE 1
    NOCYCLE
    CACHE 20
    ALL;


    Thank you...

    Published by: 998976 on April 18, 2013 04:37

    Published by: 998976 on April 18, 2013 04:38

    Hello

    All the numbers in a CREATE SEQUENCE statement are literals; no other types of numeric expressions are allowed.
    You need dynamic SQL statements to do something like what you want. For example:

    COLUMN     seq_start_col     NEW_VALUE  seq_start
    
    SELECT     1 + MAX (val)     AS seq_start_col
    FROM     table_x;
    
    CCREATE SEQUENCE TEST_SEQ.NEXTVAL
    START WITH  &seq_start
    MAXVALUE 9999999999999999999999999999
    MINVALUE 1
    NOCYCLE
    CACHE 20
    NOORDER;
    
  • Update of Table, summarizing the content of the separate column.

    Hi all

    Small update problem: -.

    CREATE THE TABLE:
     
    CREATE TABLE TestTab10
    (
    GROUPID VARCHAR2(10),
    ITEMS_1 NUMBER(2), 
    ITEMS_2 NUMBER(2),
    ITEMS_3 NUMBER(2),
    TOT_ITEMS VARCHAR(50),
    SEQNO NUMBER(10)
    );
    DATA: -.
     
    INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10001','12','13','','','123456');
    INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10001','12','','16','','123457');
    INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10002','','','','','123458');
    INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10003','','13','','','123459');
    INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10003','','13','','','123460');
    INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10003','','13','','','123461');
    INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10004','11','13','','','123462');
    INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10004','','12','','','123463');
    INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10004','','13','14','','123464');
    Select * from TestTab10;
    GROUPID       ITEMS_1    ITEMS_2    ITEMS_3 TOT_ITEMS                                               SEQNO
    ---------- ---------- ---------- ---------- -------------------------------------------------- ----------
    10001              12         13                                                                   123456
    10001              12                    16                                                        123457
    10002                                                                                              123458
    10003                         13                                                                   123459
    10003                         13                                                                   123460
    10003                         13                                                                   123461
    10004              11         13                                                                   123462
    10004                         12                                                                   123463
    10004                         13         14                                                        123464
    Desired results: -.
    GROUPID       ITEMS_1    ITEMS_2    ITEMS_3 TOT_ITEMS                                               SEQNO
    ---------- ---------- ---------- ---------- -------------------------------------------------- ----------
    10001              12         13            121316                                                 123456
    10001              12                    16 121316                                                 123457
    10002                                                                                              123458
    10003                         13            13                                                     123459
    10003                         13            13                                                     123460
    10003                         13            13                                                     123461
    10004              11         13            11131214                                               123462
    10004                         12            11131214                                               123463
    10004                         13         14 11131214                                               123464
    I need to update the Tot_items column with the number of distinct elements which is held within each groupid.

    The ideas people?

    Thanks in advance.

    Lack OP wants ordered items:

    merge
      into  testtab10 a
      using (
             with t as (
                        select  rowid rid,
                                listagg(items_1 || ',' || items_2 || ',' || items_3,',')
                                  within group (order by seqno)
                                  over(partition by groupid) items
                            from  testtab10
                       )
             select  rid,
                     xmlquery(
                              'string-join(for $n in distinct-values(ora:tokenize($str,",")) order by xs:integer($n) return $n,",")'
                              passing ',' || items as "str"
                              returning content
                             ) tot_items
               from  t
            ) b
      on (a.rowid = b.rid)
      when matched
        then
          update
            set a.tot_items = b.tot_items
    /
    
    9 rows merged.
    
    SQL>  select  *
      2     from  testtab10
      3  /
    
    GROUPID       ITEMS_1    ITEMS_2    ITEMS_3 TOT_ITEMS                 SEQNO
    ---------- ---------- ---------- ---------- -------------------- ----------
    10001              12         13            12,13,16                 123456
    10001              12                    16 12,13,16                 123457
    10002                                                                123458
    10003                         13            13                       123459
    10003                         13            13                       123460
    10003                         13            13                       123461
    10004              11         13            11,12,13,14              123462
    10004                         12            11,12,13,14              123463
    10004                         13         14 11,12,13,14              123464
    
    9 rows selected.
    
    SQL>
    

    SY.

  • Update a table of the source - duplicates exist in the source

    Hi all

    I need a logic to know how to update a target from the source table. It is here in source table contains duplicate data.
    Oracle version is 10.2.0.3.0
    OS - Sun Solaris

    Target table - fields A, B, and C. A and B are primary keys.

    A, B AND C
    1 1
    1 2
    2 2
    2 1

    Table of the source - no primary key.

    A, B AND C
    1 1 2
    1 1 2
    1 1 3
    2 1 4

    From the fields A and B, column C must be updated on the source table.

    In the target table, 4 ranks should get updated to the value 4.
    In the target table - for the first row in the source table, the 3 first lines are adapting. I'm fine with all values (2,2,3).
    In the target table - for the second and third rows, the value of c must be null.
    Currently I'm updating it through cursor. but it takes a lot of time.
    In production, less than one percent of the files are duplicate records. It asked me to update the right folders with regular update instruction and duplicate with the slider or other logic records. where less than one per 100 records will be be curly to the cursor. Basically, the direction as to reduce the load on the slider.

    Your help is most appreciated.

    Thank you

    Try a different USING clause:

    using (select a, b, c, d
           from
              (select a, b, c, d
                     ,row_number() over (partition by a, b order by c) rn
               from   s
              )
           where rn = 1
          ) s
    

    This will select the first row (numerically) within each combination, b. If you want the last line add a DESC in the order of.

  • DB trigger error - update even table in the script of the trigger

    Hi all
    I have a table tab1, whenever any update is done on this table on column col1 and col2 also needs to get the update. (These are related to user forms can be updated only col1 form frontend)
    So I created a trigger as follows.
    ----------------
    CREATE OR REPLACE TRIGGER tri1
    AFTER UPDATE
    ON tab1
    FOR EACH LINE
    WHERE (NEW.col1 = 'YES')
    DECLARE
    PRAGMA AUTONOMOUS_TRANSACTION;
    BEGIN
    Tab1 SET col2 = 1 UPDATE
    WHERE transaction_id =: OLD.transaction_id;
    COMMIT;
    END;
    --------
    When there is no update on this table, I get following error. Please let me know if I'm missing something.
    ORA-00060: Deadlock detected while you wait resource
    ORA-06512: at "user1.tab1", line 5
    ORA-04088: error during execution of trigger 'user1.tab1 '.
    Please let me know if I'm not clear. Thank you

    Published by: DharV on August 23, 2011 05:17

    Your transaction_id is unique?

    If this is the case, then you could perhaps use AFTER UPDATE BEFORE UPDATE:

    CREATE OR REPLACE TRIGGER tri1
    BEFORE UPDATE
    ON tab1
    FOR EACH ROW
    WHEN (NEW.col1 = 'YES')
    BEGIN
       :NEW.col2 := 1;
    END;
    

    If your transaction_id is not unique - if you really want to update more than one line in tab1 - your update cannot update the same line that the trigger has responded, even with the use of an autonomous transaction. Then you could combine the BEFORE UPDATE trigger above with your own AFTER UPDATE, but then add ROWID! =: OLD. ROWID to where clause, but it would be a bad idea because some of your lines will be updated in a single transaction and others in another transaction.

    In general the autonomous transaction is not a great way to solve the problem of changing table within a trigger. I hope that you have a unique transaction_id and can do BEFORE the UPDATE - if it is then a better way is to save the update id in an overall picture in FOR EACH ROW triggers, and only then AFTER an UPDATE fire is NOT "for each line" update the list of saved IDs

  • trigger to update a table after the use of commit_form;

    Hi, I have a master detail shipping form where I enter the details and use commit_form; to save data... after that I want to update a column named as transit in deteil table
    but the changes are not reflected.
    PROCEDURE transit_update IS
    BEGIN
           if :shipbill.billtype in ( 'Send it to site','Send it to staff','Send it to store','Send it to consumed ','send it to repair')
              then          
              update ship_1 set transit_qty = transact_qty
         where 
         billid =:shipbill.billid;
    
    
         end if ;
         
         if :shipbill.billtype in ('Received from staff','Received from site','Received from store','Received from STC')
              then          
              update ship_1 set transit_qty = 0
         where 
              billid =:shipbill.billid;
         
    
         end if ;
    END;
    I wrote it under the procedure and tried to call the block level under update post trigger but it doesn't...

    Hello
    Why not put the sub condition in PRE-INSERT/PRE-UPDATE (at the level of the blocks) of the retail block?

    IF :shipbill.billtype IN ('Send it to site','Send it to staff','Send it to store','Send it to consumed ','send it to repair') THEN
      :ship_1.transit_qty = :ship_1.transact_qty;
    ELSIF :shipbill.billtype IN ('Received from staff','Received from site','Received from store','Received from STC') THEN
      :ship_1.transit_qty = 0;
    END IF;
    

    If billtype is not simple text (filled in by the user) and then trying to find no matter what other condtion. To reduce misspellings error etc.

    -Clément

  • Update two tables at the same time?

    Hi, I'm having some trouble finding how to create a new field in both tables of the same shape. (php mysql)

    I have two paintings: a table listing the projects and

    a table listing assignments for example, a project may have more than one assignment.

    When the user submits the form the insert record server behavior creates a new project. The projectID in the project table field is an AutoNumber created in mysql.

    Now when the new assignment record is created in the assignment table must use the projectID AutoNumber to refer to the parent project.

    That's the problem, I don't know how to get the new AutoNumber the table project. I tried setting a variable from a select query to find the last record on the project table... but the problem is that it assigns the value when you load the web page. If two users loading the same page before insertion, the action takes place so both are assigned the same projectID. Of course, which is useless.

    I'm not a programmer so need help to understand this.

    See you soon,.

    How to retrieve the value of an autoincrement column:

    http://www.gotocode.com/art.asp?art_id=80&

  • Problem with update of table (using the subquery to retrieve value)

    Hello
    I update a table based on the value of the subquery.
    Here's the update statement.

    UPDATING temp xm
    SET xm.col1 = (SELECT DISTINCT col1
    Of
    (SELECT col1, col2 COUNT (col2)
    FROM table2
    WHERE col1 = xm.col1
    AND col2 = xm.col2
    GROUP BY col1)
    where col2 in (select... in the table3)
    )
    WHERE xm.col5 = < value >
    AND xm.col6 = < value >

    When I run this statement I get following error.
    ORA-00904: "XM". "" Col1 ": invalid identifier.

    Can someone help me why I get this error?
    Why doesn't the main table alias in the subquery?

    Is it possible to avoid this / re - write the query in a different way?

    Thank you

    Published by: user552703 on November 2, 2009 20:42

    You can nest only 1 level deep (referring to the table to be updated).

    Have you looked at using the MERGE command? It is "easier" perform updates of this nature, assuming you are using a recent version of Oracle (9 or MORE).

  • Unable to load is the owner of standard Interface table at the Base of the OM tables

    Hi gurus,

    I load the data of shims for orders using the standard interface for order management.

    I can see the data blocks in the table of standard interface

    Select * from apps.oe_actions_iface_all;
    gives me data from the pending requests that need to be attracted to the flat-rate import program.

    but when I run the import of order program,
    I get the following error


    Order import concurrent program

    Simultaneous program settings
    Post only: N
    Control the Source: 1064
    Order code:
    Sold to Org Id:
    Sold to Org:
    Change the sequence:
    Performance parameter: Y
    Cut the whites: N
    Operation:
    Number of Instances: 0

    Debug level: 0
    Request Id: 105961365
    Org Id: 166

    Cannot perform Action ask APPLY_HOLD
    N ° of orders found: 1
    N ° of orders imported: 1
    N ° of the commands failed: 0


    Message from the source/line/command/Seq
    1064/12715682 / / 100, you are not allowed to apply this expectation.

    End of the simultaneous programme of the Import command

    Can someone help me on why it will fail in the import order program, which would be the cause of the simultaneous program error.

    all input is much appreciated.

    Thanks adavance

    Published by: 909577 on August 24, 2012 12:01 AM

    Hello

    I have no English version (I don't want to open a session we language I'm lazy :)) This is my translation :) Order management responsibility-> Setup-> controls-> shims find you hold and look at authorization. Maybe your wrong because that pck.

    Kind regards
    Luko

  • ORA-02283: cannot change the boot sequence number

    Hi guys,.

    I want a sequence of changes starting number of 127657 to 8211200... But im not able to change the starting number please someone can help me.

    current is
    CREATE SEQUENCES WH1. INVOICENUM_SEQ
    START WITH 127657
    INCREMENT BY 1
    NOMINVALUE
    NOMAXVALUE
    NOCYCLE
    NOCACHE
    ALL


    ALTER SEQUENCE WH1. INVOICENUM_SEQ
    START WITH 8211200
    INCREMENT BY 1
    NOMINVALUE
    NOMAXVALUE
    NOCYCLE
    NOCACHE
    ALL

    Yes - the norm is to change the increment to a number that will make the bridge, a single call to NEXTVAL and then change the increment to return to what it was.

    ALTER SEQUENCE mySeq  INCREMENT 8000000; -- use the value that is the difference between the current value and what you want it to be
    
    SELECT mySeq.nextval from dual;
    
    ALTER SEQUENCE mySeq INCREMENT 1;
    
  • Drag and drop the Image sequence number

    Hello

    IM bad having to drag / drop a folder of image sequence. Folder hangs out perfectly and the window further emphasizes, but nothing happens. However when I go to FILE and IMPORT I success bringing in the sequence of images as a model.

    This problem is resolved by update fixes after effects CC (12.2.1), which is now available:

    http://Adobe.LY/AE_CC_1221

    Note the part at the end of this page on a crucial update for the creative cloud desktop application, which addresses serious problems with the SOUL, first Pro and After Effects.

  • Get the data in the table in the format of number

    Ive got this table with numbers in it, that I want to use for some simple calculations, but I get the message that the data in the table is not a number:

    The whole is in a loop for, with teller1 as in ascending order.

    code:

    var xco:Array = [180,233,271,292,292,270,231,179,124,74,34,11,9,30,70,121];
    var yco:Array = [11,33,73,124,181,232,270,290,291,271,234,183,125,72,33,11];

    for (var teller1 = 1; teller1 < 33; teller1 ++) {}
    var ringsegment_mc:Ring_1 = new Ring_1();
    ringsegment_mc.x = XCO [teller1] + kernplaats;
    ringsegment_mc.y = yco [teller1] + kernplaats;
    ringsegment_mc.addEventListener (Event.ENTER_FRAME, vernietig);
    addChild (ringsegment_mc);
    {Switch (teller1)}
    box 16:
    kernplaats = Math.Random () * 600 + 300;
    kernplaats = Number (400);
    trace (yco [teller1]);
    trace (yco [teller1] + kernplaats);
    }
    }

    If the trace functions are:

    undefined

    NaN

    so I tried to use this:

    trace (yco [3]);
    trace (yco [3] + kernplaats);

    who gave this:

    124

    524

    If something goes wrong in trying to read the table, but what? and how can it be solved.

    I don't know what you're after, but if you want to use the same loop twice, then put it inside another loop... (Note that arrays start at index 0, not 1)

    for (var i = 0; i)<2;>

    for (var teller1 = 0; teller1<16; teller1++)="">
    var ringsegment_mc:Ring_1 = new Ring_1();
    ringsegment_mc.x = XCO [teller1] + kernplaats;
    ringsegment_mc.y = yco [teller1] + kernplaats;
    ringsegment_mc.addEventListener (Event.ENTER_FRAME, vernietig);
    addChild (ringsegment_mc);
    {Switch (teller1)}
    box 16:
    kernplaats = Math.Random () * 600 + 300;
    kernplaats = Number (400);
    trace (yco [teller1]);
    trace (yco [teller1] + kernplaats);
    }
    }

    }

  • I joined creative cloud yesterday (Lightroom and Photoshop) and the assigned sequence number is not valid for the two products. shouldn't have received 1 serial number for each product?

    Any help?

    There is no serial number used for your subscription of the cc.  you use your adobe ID to validate your downloads, https://creative.adobe.com/

Maybe you are looking for