Update a column-based

Hi all

Let us examine below in Oracle 11 g:

create table xx_test1 (line_num  number, line_group_num number, type varchar2(25));


insert into XX_TEST1 values('',1, 'ITEM');
insert into XX_TEST1 values('',1, 'TAX');
insert into XX_TEST1 values('',2, 'ITEM');
insert into XX_TEST1 values('',2, 'TAX');
insert into xx_test1 values('',3, 'ITEM');
insert into xx_test1 values('',3, 'TAX');

I want the line_number update based on type and line_group_num columns column.

So necessary result:

  LINE_NUM LINE_GROUP_NUM TYPE
---------- -------------- ----
         1              1 ITEM 
         2              2 ITEM 
         3              3 ITEM 
         4              1 TAX  
         5              2 TAX  
         6              3 TAX  

That means I want the sequence to be - items in the first place, only the lines of the TAX.

Line_group_number is the column that combines the tax line to the line item.

Any ideas?

Regrads,

Stoyanov.

Hello

user11340233 wrote:

Hi all

Let us examine below in Oracle 11 g:

  1. create table xx_test1 (type number line_num, line_group_num, varchar2 (25));
  2. insert into XX_TEST1 values (", 1,"ITEM");
  3. insert into XX_TEST1 values (", 1,"TAX");
  4. insert into XX_TEST1 values (", 2,"ITEM");
  5. insert into XX_TEST1 values (", 2,"TAX");
  6. insert into xx_test1 values (", 3,"ITEM");
  7. insert into xx_test1 values (", 3,"TAX");

I want the line_number update based on type and line_group_num columns column.

So necessary result:

  1. TYPE OF LINE_GROUP_NUM LINE_NUM
  2. ---------- -------------- ----
  3. 1 1 ARTICLE
  4. 2 2 POINT
  5. 3 POINT 3
  6. 4 1 THE TAX
  7. 5 TAX 2
  8. 6 TAX 3

That means I want the sequence to be - items in the first place, only the lines of the TAX.

Line_group_number is the column that combines the tax line to the line item.

Any ideas?

Regrads,

Stoyanov.

You can do this by using the ROW_NUMBER function analytical in a MERGE statement.  For example:

MERGE INTO dst xx_test1

WITH THE HELP OF)

SELECT line_group_num, type

ROW_NUMBER () (ORDER BY TYPE, line_group_num) AS line_num

OF xx_test1

)              src

WE (dst.line_group_num = src.line_group_num

AND dst.type = src.type

)

WHEN MATCHED THEN UPDATE

SET dst.ine_num = scr.line_num

;

This assumes that the combination (type, line_group_num) is unique, and none of these columns are NULL, like your sample data.

If this isn't the case, then the above statement needs to be changed a little, but only a louis577.

Tags: Database

Similar Questions

  • Compare multiple columns and update a column based on the comparison

    Hi all

    I have to update the column STATUS of the slot structure of the table.

    Status should be 'P' if all the columns count are equal on the other should be "F".

    The value of the column can be "NA'. If the value is NA, then avoid this comparison column; compare only other 3 columns.

    My output should look like below.

    State of cnt1, cnt2 cnt3 ID cnt4

    1   4       4       4     4       P

    2   4       5       4     4       F

    3 4 4 NA 4 P

    NA 4 4 3 4

    I tried with the statemnt with BOX WHEN conditions and DECODE UPDATE, but could not succeed, can someone please help

    To do this, if you use my statement in response #11 box (Re: Re: comparison of multi-column and update a column based on the comparison of)

  • In the form of table-update a column based on the other

    Greetings,

    I want to update a column based on the value of another column in a tabular presentation. What should I use? Calculation or validation process?

    -Vatsa

    Yes, get rid of the update of "pims_component" - this is the cause of the error table mutation - and simply set

    : new.state_ind: = Ls_state;

    CITY

  • update of column based on another column

    Hi all

    I want to update the column 2 of the table based on the value of update in column 1 and the existing value in column 1

    Assume that table1 has columns ID, col1 and col2

    I update col2 based on the update to col1 value and comparing the existing value of col1 in the table.

    trying to decode, I think it should work.

    Thank you.

    Not like that.

    You change a column of type CHAR, VARCHAR2 column, right? Thus, the data will be same. (Completed with space). For the new data inserted into a column VARCHAR2 TRIM is not necessary.

  • update of column based on the sum of the data from another table

    I have two tables:

    Table1 (col1, col2, col3, col4, val1, status) Table2 (col1, col2, col3, col4, val2)

    For Table1 and Table2, column (col1, col2, col3, col4) are the primary key of composit.

    Table2 could have duplicated lines, that's why I want to group by (col1, col2, col3, col4) and sum (val2)

    After that, I want to update Table1.val1 with the value of sum (Table1.val2) where Table1.col1 = Table2.col1 and Table1.col2 = Table2.col2 and Table1.col3 = Table2.col3 and Table1.col4 = Table2.col4 and status = 'V '.

    I did something like this:

    UPDATE Table1 SET val1 = (

       

    WHERE Table1.col1 = t_sommevbrute.col1 and Table1.col2 = t_sommevbrute.col2 and Table1.col3 = t_sommevbrute.col3 and Table1.col4 = t_sommevbrute.col4)

    Could someone help me please? Thank you

    merge into table1 t1

    using (select col1, col2, col3, col4, sum (val2) val2

    from table2

    Group

    by col1, col2, col3, col4) t2

    on (t1.col1 = t2.col1 t1.col2 = t2.col2 and t1.col3 = t2.col3 and t1.col4 = t2.col4 and)

    When matched then

    update set t1.val1 = t2.val2;

  • update of column based on the values of the same table

    I have the T1 table with 4 columns "col1", "col2", "col3", "col4", "col5", "col6" as follows

    Col1 Col2 Col3 Col4 Col5 Col6
    1111 Ville1 C AA DDD A1
    2222 city SD HHH A1 1
    3333 City2 B EE OOO
    4444 City 1 B JJ SSS A1
    5555 City2 C KK VVV
    6666 City2 RR QQQ
    7777 City2 B BBB XX

    I've already updated column value 6 'A1' where the 2 column is 'Ville1 '.

    Now, I want to update Col. 6 where col2 is the of ' with the following conditions
    If Col 3 = 'B', then Col6 should be = col4
    Otherwise, it should be = col5

    SET col6 = DECODE(col3,'B',col4,col5)
    "WHERE col2 = s"

  • How can I update the column based date?

    Hello..

    first I want to thank everyone for the help that you are given...

    I have a table that looks like this:

    the air course date

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

    X 0 NOV2013

    Y 900 OCT2013

    Z 800 OCT2013

    X 700 OCT2013

    Y 500 NOV2013

    X 100 NOV2011

    X 200 NOV2012

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

    I need a SQL expression for this

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

    If the price is 0

    then select the average price for the same air, and the same month but different year

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

    for example in the table...

    When noncompliance X is 0 to DATE price NOV2013

    THEN select the average price for product X in NOV2012 NOV2011 AND

    THAT will be (100 200) = 100

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

    Naïve...

    Hello

    This?

    Note: I pushed since your unique records PROD, D

    SQL > select * from t1;

    D PRICE OF PROD

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

    X 0 01.11.2013

    Y 900 01.10.2013

    Z 800 01.10.2013

    X 700 01.10.2013

    Y 500 01.11.2013

    X 100 01.11.2011

    X 200 01.11.2012

    7 selected lines

    SQL >

    SQL > select q1.prod, q1.price, q1.d, avg (q2.price) avg_price

    2 from t1 t1

    3 join left t1 t2

    4 on q2.prod = q1.prod

    5 and trunc (q2.d, 'yyyy')! = trunc (q1.d, 'yyyy')

    6 and to_char (q2.d, 'mm') = to_char (q1.d, 'mm')

    Group 7 by q1.prod, q1.price, q1.d

    8.

    PROD AVG_PRICE D PRICE

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

    X 700 01.10.2013

    200 X 01.11.2012 50

    X 0 01.11.2013 150

    Z 800 01.10.2013

    Y 900 01.10.2013

    Y 500 01.11.2013

    X 100 01.11.2011 100

    7 selected lines

    SQL >

    SQL >

    SQL >

    SQL > fusion in t1

    2. using (select q1.prod, q1.price, q1.d, avg (q2.price) avg_price

    3 T1 t1

    4 join left t1 t2

    5 on q2.prod = q1.prod

    6 and trunc (q2.d, "yyyy")! = trunc (q1.d, "yyyy")

    7 and to_char (q2.d, 'mm') = to_char (q1.d, 'mm')

    q 8 group of q1.prod, q1.price, q1.d)

    9 on (q.prod = t1.prod and t1.d = q. at)

    10 when matched then

    11 update set t1.price = q.avg_price where t1.price = 0

    12.

    1 row merged

    SQL >

    SQL >

    SQL > select * from t1;

    D PRICE OF PROD

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

    X 150 01.11.2013

    Y 900 01.10.2013

    Z 800 01.10.2013

    X 700 01.10.2013

    Y 500 01.11.2013

    X 100 01.11.2011

    X 200 01.11.2012

    7 selected lines

    SQL >

    ----

    Ramin Hashimzade

  • Update line in the column-based database

    Hello

    I am trying to find a way to update a row that has a SQL database based on two columns. If the command and the match number sensor order number and sales sensor that already exists in the database, I want to update the column of reading of the sensor. If not exists then I want that it creates a new line. How would I go to do this?

    Thank you

    Chris

    You can use the tools of DB Query.vi Execute. Here is an example of a MS Access 2010 database where a column value is updated in all rows satisfying the WHERE conditions.

    Ben64

  • update of column with the number of sequence based on the condition


    Hello

    Version of DB: database Oracle 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production

    Here's the script to reporduce:

    CREATE TABLE T2
    (
    PARAMLOCATION NVARCHAR2 (16).
    PARAMTYPE VARCHAR2 (3 BYTE),
    PARAMNUM VARCHAR2 (3 BYTE)
    )

    Insert into T2
    (PARAMLOCATION)
    Values
    ('49');
    Insert into T2
    (PARAMLOCATION)
    Values
    (« 12 ») ;
    Insert into T2
    (PARAMLOCATION)
    Values
    (« 50 ») ;
    Insert into T2
    (PARAMLOCATION, PARAMTYPE)
    Values
    ('loc51', 'B');
    Insert into T2
    (PARAMLOCATION, PARAMTYPE)
    Values
    ('loc52', 'B');
    Insert into T2
    (PARAMLOCATION, PARAMTYPE)
    Values
    ('loc53', 'B');
    Insert into T2
    (PARAMLOCATION)
    Values
    ("loc54");
    Insert into T2
    (PARAMLOCATION)
    Values
    ("loc55");
    Insert into T2
    (PARAMLOCATION, PARAMTYPE)
    Values
    ('aoc01', 'I');
    Insert into T2
    (PARAMLOCATION, PARAMTYPE)
    Values
    ('aoc02', 'I');
    Insert into T2
    (PARAMLOCATION)
    Values
    ("loc58");
    Insert into T2
    (PARAMLOCATION, PARAMTYPE)
    Values
    ("doc03", "DL");
    Insert into T2
    (PARAMLOCATION, PARAMTYPE)
    Values
    ("doc02", "DL");
    Insert into T2
    (PARAMLOCATION, PARAMTYPE)
    Values
    ("doc01", "DL");

    I should update the column in table (paramnum) function sequential paramtype as this: also you can not order in paramlocation, its like that paramlocation comes first start sequence ordering from there based on paramtype.

    PARAMLOCATIONPARAMTYPEPARAMNUM
    49
    12
    50
    loc51B1
    loc52B2
    loc53B3
    loc54
    loc55
    aoc01AI1
    aoc02AI2
    loc58
    doc03DL1
    doc02DL2
    doc01DL3

    Please advice.

    Hello

    I'll assume you have a column called load_order, which corresponds to the order of the lines:

    CREATE TABLE T2
    (
    NUMBER OF LOAD_ORDER
    PARAMLOCATION NVARCHAR2 (16).
    PARAMTYPE VARCHAR2 (3 BYTE),
    PARAMNUM VARCHAR2 (3 BYTE)
    ) ;

    Insert into T2
    (LOAD_ORDER, PARAMLOCATION)
    Values
    (1, '49');
    Insert into T2
    (LOAD_ORDER, PARAMLOCATION)
    Values
    (2, '12');
    Insert into T2
    (LOAD_ORDER, PARAMLOCATION)
    Values
    (3, '50');
    Insert into T2
    (LOAD_ORDER, PARAMLOCATION, PARAMTYPE)
    Values
    (5, 'loc51', 'B');
    Insert into T2
    (LOAD_ORDER, PARAMLOCATION, PARAMTYPE)
    Values
    (8, 'loc52', 'B');
    Insert into T2
    (LOAD_ORDER, PARAMLOCATION, PARAMTYPE)
    Values
    (13, 'loc53', 'B');
    Insert into T2
    (LOAD_ORDER, PARAMLOCATION)
    Values
    (13.2, "loc54");
    Insert into T2
    (LOAD_ORDER, PARAMLOCATION)
    Values
    (13.5, 'loc55');
    Insert into T2
    (LOAD_ORDER, PARAMLOCATION, PARAMTYPE)
    Values
    (50, 'aoc01', 'I');
    Insert into T2
    (LOAD_ORDER, PARAMLOCATION, PARAMTYPE)
    Values
    (80, 'aoc02', 'I');
    Insert into T2
    (LOAD_ORDER, PARAMLOCATION)
    Values
    (81, 'loc58');
    Insert into T2
    (LOAD_ORDER, PARAMLOCATION, PARAMTYPE)
    Values
    (82, "doc03", "DL");
    Insert into T2
    (LOAD_ORDER, PARAMLOCATION, PARAMTYPE)
    Values
    (83, "doc02", "DL");
    Insert into T2
    (LOAD_ORDER, PARAMLOCATION, PARAMTYPE)
    Values
    (99, "doc01", "DL");

    Any data type, this column is or what are the values it contains, as long as you can derive from the order of the rows of values in the column.  (Of course, the values can be consecutive integers, only they do not have to be).  If you do not have this type of column, you don't have any order to your lines, and what you request is impossible.

    Since you have a load_order column, here's a way to get the results you requested:

    MERGE INTO dst t2

    WITH THE HELP OF)

    WITH got_grp AS

    (

    SELECT load_order

    paramlocation

    paramtype

    ROW_NUMBER () OVER (ORDER BY load_order)

    -ROW_NUMBER () OVER (PARTITION BY CASE

    WHEN paramtype IS NULL

    THEN 0

    END

    ORDER BY load_order

    ) AS the grp

    THE t2

    )

    SELECT load_order

    paramlocation

    ROW_NUMBER () OVER (PARTITION BY grp

    ORDER BY load_order

    ), Paramnum

    OF got_grp

    WHERE the paramtype IS NOT NULL

    ) CBC

    WE (dst.paramlocation = src.paramlocation)

    WHEN MATCHED THEN UPDATE

    SET dst.paramnum = src.paramnum

    ;

    Results:

    LOAD_ORDER PARAMLOCATION BY

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

    1 49

    2 12

    3 50

    loc51 5 B 1

    loc52 8 B 2

    13 loc53 B 3

    13.2 loc54

    loc55 13.5

    50 aoc01 AI 1

    80 aoc02 AI 2

    loc58 81

    1 DL of 82 doc03

    2 DL doc02 83

    3 DL of 99 doc01

  • How update the column in the table based on the value selected in apex4.1

    Hi all
    I have the following tables,
    leave_type table,it has the following fields,
    1.emp_name,
    2.sick
    3.casual
    and it has the values as follows,
    emp_name                  sick             casual
    guru                           10                10
    mishra                         10                10
    leave_master table and it includes the following fields
    1.emp_name,
    2.leave_type
    3.no_of_days
    I have the form based on the table "leave_master"
    Here, the leave_type has the LOV which includes.
    sick and casual.

    When the form is filled out and clicked on the button submit,
    I need to update the column leave_type in table leave_type,
    for example,.
    if 
    emp_name:guru
    leave_type:sick
    no_of_days:3
    then I want to update the leave_type column,
    sick sick = - no_of_days for the 'guru' of name
    That is to say, ill = 10-3 = 7

    then the leave_type of the table must be,
    emp_name                       sick             casual
    guru                                 7                10
    mishra                              10               10
    someone can such me what code or method I can use?
    Thank you.

    Published by: Gurujothi on May 24, 2012 21:54

    Published by: Gurujothi on May 24, 2012 21:54

    Try something like this...

    BEGIN
    IF: PXX_LEAVE_TYPE = "Sick" THEN
    UPDATE LEAVE_TYPE
    THE PATIENT VALUE = SICK -: PXX_NO_OF_DAYS
    WHERE EMP_NAME =: PXX_EMP_NAME;
    ON THE OTHER
    UPDATE LEAVE_TYPE
    DEFINE CASUAL = CASUAL -: PXX_NO_OF_DAYS
    WHERE EMP_NAME =: PXX_EMP_NAME;
    END IF;
    COMMIT;
    END;

  • Update the value of the column based on another value of the column to another table

    Hi all

    I have something very confused me and need your help.

    Having two tables A and B.

    Table A have 2 column (+ id + and desc1)

    Table B have column 2 also (+ transnum + and desc2)

    Now, I want to update the column desc2 of table B identical desc1 of table was where transnum of Table B same as the id of the table has.

    I use this SQL

    update of a2 set a2.desc2 = a1.desc1 of a2 on a2.transnum = a1.id inner join a1

    but this error occurs

    Error from line 5 in order:
    update of a2 set a2.desc2 = a1.desc1 of a2 on a2.transnum = a1.id inner join a1
    Error in the command line: 5 column: 35
    Error report:
    SQL error: ORA-00933: SQL not correctly completed command
    * 00933. 00000 - "command not properly ended SQL."
    * Question: *.

    * Action. *

    Hope someone can help me. TQ for help...
    SQL> create table a1 (id number(2),des varchar2(10));
    
    Table created.
    
    SQL> create table b1 (transnum number(2),des varchar2(10));
    
    Table created.
    
    SQL> insert into a1 values (1,'maran');
    
    1 row created.
    
    SQL> insert into b1 values (1,'ram');
    
    1 row created.
    
    SQL> commit;
    
    Commit complete.
    
    SQL> update b1 set des=(select des from a1 where b1.transnum=a1.id);
    
    1 row updated.
    
    SQL> select * from b1;
    
      TRANSNUM DES
    ---------- ----------
             1 maran
    
  • Display a column based on another column

    Hello

    I work in the Apex 4.2.

    I have a tabular presentation based on a query.

    In this form, I have a column of link change with an icon. When I click it, I open a new page with the details of my record.

    I want that this column appears only when the user is entitled.

    So, I got in my request a new column based on a Pl/sql function that returns 1 when the logged-on user has the privilege package update the record.

    I call this new column "can_update."

    After that, I changed the "conditional display" property of my edit_link column.

    In type of condition, I put: "value for the element / the expression 1 column = Expression 2.

    I put in the expression 1: can_update

    I put in the expression 2: 1

    But it does not work as I want. colonm "edit_link" never appears.

    and the can_update column return the good value 1 or 0 on depend on the recording.

    Anyone has an idea on what I didi wrong?

    Thank you.

    Laurent.

    I found a solution to my problem.

    I have a column in my query that return 'none' or 'inline' when I have the privilege to update my file and thus, the column "edit_link."

    Thos query column name is link_disp

    And in the "link attribute" property, the "link in the column" Section of my edit_link, I add: "style =" display: #LINK_DISP #»»

    and it works well

    Laurent.

  • In the form of table-update of rows based on the selection of the checkbox

    Hi all

    I have a tabular layout with line selector. I need to update manually checked columns, how would write a process audited records updated?

    Something like this:
    BEGIN     
         FOR i in 1..apex_application.g_f01.count LOOP
    
              IF apex_application.g_f01(i) is not null THEN
                   UPDATE TEST_USERS
                        set USER_ID = :P14_TO
                   WHERE rowid = :APEX$ROW_ID;
                   COMMIT;
              END IF;
         END LOOP;
    END;
    Thank you very much.

    You can refer to the line that you want to process through the value stored in the box.

    If you use apex_application.g_f01 (i) to make reference to the line and you want to update the row based on the ROWID in your request, your SQL query should have the box as follows:

    apex_item. CheckBox2 (1, rowid)

    Then your PLSQL process would be like this:

    BEGIN
         FOR i in 1..apex_application.g_f01.count LOOP
    
              IF apex_application.g_f01(i) is not null THEN
                   UPDATE TEST_USERS
                        set USER_ID = :P14_TO
                   WHERE rowid = APEX_APPLICATION.G_F01(i);
                   COMMIT;
              END IF;
         END LOOP;
    END;
    

    I hope this helps.

    Cheers, Pete

  • Automatically update the column in the table in OBIEE

    Hi people,

    I have a requirement to say I need to update a column of table based on a condition, but this update should happen on a daily basis (I mean that it would be held once per day) by checking if all the records in this column meets the condition then update

    example:-column = 'pending', then using the "approved". As records of transactions every day in the table lights. OBIEE should check and update the line so the next time it does not show this line as "pending".

    I thought of 2 approaches to this
    (1) through the write-back, it is possible to update but manually (the question is it can't be automated or on demand on daily basis and update multiple records on a go)
    (2) write a stored procedure or a function of update, but how can I perform this procedure either regular or run once daily.how to use it?

    Any thoughts on the above two points or any method you can think off the coast.

    Any help is appreciated!

    See you soon,.
    KK

    Murielle,

    This shud be easy...
    -Create a direct database... with the Update statement
    for example: Update table set col = "Approved" where col = 'pending '.
    -Create an ibot using the RFI above and plan on a daily basis.

    This will update the complete table with the new value on a daily basis based on the State

  • Hide column based on the State in BI Publisher Excel Template

    Hello

    I have a requirement to hide a column based on certain conditions in the Excel of BI Publisher model. I am newbie for BI Publisher excel template. Anyone can provide some advice on this?

    I need this emergency. Any kind of help would be very appreciated.

    Thank you

    Renu

    Hi Renu,

    Recently, I came across a similar requirement, and I went to without BEEP features to hide and show columns during execution, unlike the RTF.

    But I did it in Excel model with the help of the Macro. It works fine for me.

    Please see below

    1. based on a cell value 'A', I have to hide the column

    2 written a simple if statement in macro to get the value of 'A' and do the hide/show

    3. you need to do this only in "ThisWorkbook" macro is executed when the excel output is open.

    Thank you

    Mani

Maybe you are looking for