Update statement for multiple records

i have table a and table b
common col in both the tables is emp_id
in table b i have district_id
which i want to update in table a.... column district_id for all the employees
how to write update statement for this
Edited by: user10873676 on Oct 17, 2011 8:00 AM

Based on your current description, we have something like this...
SQL> create table a (emp_id number)
  2  /
Table created.
SQL>
SQL> create table b (emp_id number, district_id number)
  2  /
Table created.
SQL>
SQL> insert into a (emp_id)
  2  select rownum from dual connect by rownum <= 10
  3  /
10 rows created.
SQL>
SQL> insert into b (emp_id, district_id)
  2  select rownum, 10-rownum from dual connect by rownum <= 10
  3  /
10 rows created.
SQL>
SQL> update b
  2  set district_id = 1
  3  /
10 rows updated.
SQL>
SQL> select * from a;
    EMP_ID
         1
         2
         3
         4
         5
         6
         7
         8
         9
        10
10 rows selected.
SQL> select * from b;
    EMP_ID DISTRICT_ID
         1           1
         2           1
         3           1
         4           1
         5           1
         6           1
         7           1
         8           1
         9           1
        10           1
10 rows selected.Which I'm sure is NOT what you want as the update on table b has nothing to do with table a, and we have no idea what the district_id should be updated with.

Similar Messages

  • Problem in UPDATE statement In Multiple Record Block

    Hi Friends,
    I have problem in update Statement for updating the record in multiple record data Block.
    I have two data Block the master block is single Record block and the 2nd data block is Multiple Record data Block.
    I am inserting the fields like category,and post_no for partiular job in single data block
    Now in second Multiple Record Data Block,i am inserting the multiple record for above fileds like no. of employees work in the position
    There is no problem in INSERT Statement as it is inerting all record But whenever i want to update particular Record (in Multiple Block) of employee for that category and Post_no
    then its updating all the record.
    my code is Bellow,
    IF v_count 0 THEN
    LOOP
    IF :SYSTEM.last_record 'TRUE' THEN
    UPDATE post_history
    SET idcode = :POST_HISTORY_MULTIPLE.idcode,
    joining_post_dt = :POST_HISTORY_MULTIPLE.joining_post_dt,
    leaving_post_dt = :POST_HISTORY_MULTIPLE.leaving_post_dt,
    entry_gp_stage = :POST_HISTORY_MULTIPLE.entry_gp_stage
    WHERE post_no = :POST_HISTORY_SINGLE.post_no
    AND category = :POST_HISTORY_SINGLE.category
    AND roster_no = :POST_HISTORY_SINGLE.roster_no;
    AND idcode = :POST_HISTORY_MULTIPLE.idcode;
    IF SQL%NOTFOUND THEN
    INSERT INTO post_history(post_no,roster_no,category,idcode,joining_post_dt,leaving_post_dt,entry_gp_stage)
    VALUES(g_post_no, g_roster_no, g_category, :POST_HISTORY_MULTIPLE.idcode, :POST_HISTORY_MULTIPLE.joining_post_dt,
    :POST_HISTORY_MULTIPLE.leaving_post_dt,:POST_HISTORY_MULTIPLE.entry_gp_stage);
    END IF;
    next_record;
    ELSIF :SYSTEM.last_record = 'TRUE' THEN
    UPDATE post_history
    SET idcode = :POST_HISTORY_MULTIPLE.idcode,
    joining_post_dt = :POST_HISTORY_MULTIPLE.joining_post_dt,
    leaving_post_dt = :POST_HISTORY_MULTIPLE.leaving_post_dt,
    entry_gp_stage = :POST_HISTORY_MULTIPLE.entry_gp_stage
    WHERE post_no = :POST_HISTORY_SINGLE.post_no
    AND category = :POST_HISTORY_SINGLE.category
    AND roster_no = :POST_HISTORY_SINGLE.roster_no;
    AND idcode = :POST_HISTORY_MULTIPLE.idcode;
    IF SQL%NOTFOUND THEN
    INSERT INTO post_history(post_no,roster_no,category,idcode,joining_post_dt,leaving_post_dt,entry_gp_stage)
    VALUES (g_post_no,g_roster_no,g_category,:POST_HISTORY_MULTIPLE.idcode,
    :POST_HISTORY_MULTIPLE.joining_post_dt,:POST_HISTORY_MULTIPLE.leaving_post_dt,:POST_HISTORY_MULTIPLE.entry_gp_stage);
    END IF;
    EXIT;
    END IF;
    END LOOP;
    SET_ALERT_PROPERTY('user_alert',ALERT_MESSAGE_TEXT, 'Record Updated successfuly' );
    v_button_no := SHOW_ALERT('user_alert');
    FORMS_DDL('COMMIT');
    CLEAR_FORM(no_validate);
    Please Guide me
    Thanks in advence

    As you do a loop over all the records in the block, of course every record is updated.
    Also, what you do is not the way is intended to be used. In general, you base a block on a table,then there is no need at all for writing INSERT's or UPDATE's. Forms also know's then, which records to be updated and which not.

  • Problem In Update Statement In Multiple Record Data Block

    Hi Friends,
    I have problem in update Statement for updating the record in multiple record data Block.
    I have two data Block the master block is single Record block and the 2nd data block is Multiple Record data Block.
    I am inserting the fields like category,and post_no for partiular job in single data block
    Now in second Multiple Record Data Block,i am inserting the multiple record for above fileds like no. of employees work in the position
    There is no problem in INSERT Statement as it is inerting all record But whenever i want to update particular Record (in Multiple Block) of employee for that category and Post_no
    then its updating all the record.
    my code is Bellow,
    IF v_count <> 0 THEN
    LOOP
    IF :SYSTEM.last_record <> 'TRUE' THEN
    UPDATE post_history
    SET idcode = :POST_HISTORY_MULTIPLE.idcode,
    joining_post_dt = :POST_HISTORY_MULTIPLE.joining_post_dt,
    leaving_post_dt = :POST_HISTORY_MULTIPLE.leaving_post_dt,
    entry_gp_stage = :POST_HISTORY_MULTIPLE.entry_gp_stage
    WHERE post_no = :POST_HISTORY_SINGLE.post_no
    AND category = :POST_HISTORY_SINGLE.category
    AND roster_no = :POST_HISTORY_SINGLE.roster_no;
    AND idcode = :POST_HISTORY_MULTIPLE.idcode;
    IF SQL%NOTFOUND THEN
    INSERT INTO post_history(post_no,roster_no,category,idcode,joining_post_dt,leaving_post_dt,entry_gp_stage)
    VALUES(g_post_no, g_roster_no, g_category, :POST_HISTORY_MULTIPLE.idcode, :POST_HISTORY_MULTIPLE.joining_post_dt,
    :POST_HISTORY_MULTIPLE.leaving_post_dt,:POST_HISTORY_MULTIPLE.entry_gp_stage);
    END IF;
    next_record;
    ELSIF :SYSTEM.last_record = 'TRUE' THEN
    UPDATE post_history
    SET idcode = :POST_HISTORY_MULTIPLE.idcode,
    joining_post_dt = :POST_HISTORY_MULTIPLE.joining_post_dt,
    leaving_post_dt = :POST_HISTORY_MULTIPLE.leaving_post_dt,
    entry_gp_stage = :POST_HISTORY_MULTIPLE.entry_gp_stage
    WHERE post_no = :POST_HISTORY_SINGLE.post_no
    AND category = :POST_HISTORY_SINGLE.category
    AND roster_no = :POST_HISTORY_SINGLE.roster_no;
    AND idcode = :POST_HISTORY_MULTIPLE.idcode;
    IF SQL%NOTFOUND THEN
    INSERT INTO post_history(post_no,roster_no,category,idcode,joining_post_dt,leaving_post_dt,entry_gp_stage)
         VALUES (g_post_no,g_roster_no,g_category,:POST_HISTORY_MULTIPLE.idcode,
              :POST_HISTORY_MULTIPLE.joining_post_dt,:POST_HISTORY_MULTIPLE.leaving_post_dt,:POST_HISTORY_MULTIPLE.entry_gp_stage);
    END IF;
    EXIT;
    END IF;
    END LOOP;
    SET_ALERT_PROPERTY('user_alert',ALERT_MESSAGE_TEXT, 'Record Updated successfuly' );
    v_button_no := SHOW_ALERT('user_alert');
    FORMS_DDL('COMMIT');
    CLEAR_FORM(no_validate);
    Please Guide me
    Thanks in advence

    UPDATE post_history
    SET idcode = :POST_HISTORY_MULTIPLE.idcode,
    joining_post_dt = :POST_HISTORY_MULTIPLE.joining_post_dt,
    leaving_post_dt = :POST_HISTORY_MULTIPLE.leaving_post_dt,
    entry_gp_stage = :POST_HISTORY_MULTIPLE.entry_gp_stage
    WHERE post_no = :POST_HISTORY_SINGLE.post_no
    AND category = :POST_HISTORY_SINGLE.category
    AND roster_no = :POST_HISTORY_SINGLE.roster_no;
    AND idcode = :POST_HISTORY_MULTIPLE.idcode;
    UPDATE post_history
    SET idcode = :POST_HISTORY_MULTIPLE.idcode,
    joining_post_dt = :POST_HISTORY_MULTIPLE.joining_post_dt,
    leaving_post_dt = :POST_HISTORY_MULTIPLE.leaving_post_dt,
    entry_gp_stage = :POST_HISTORY_MULTIPLE.entry_gp_stage
    WHERE post_no = :POST_HISTORY_SINGLE.post_no
    AND category = :POST_HISTORY_SINGLE.category
    AND roster_no = :POST_HISTORY_SINGLE.roster_no;
    AND idcode = :POST_HISTORY_MULTIPLE.idcode;These update statements are without where clause, so it will update all records.
    If it is specific to oracle forms then u may get better help at Forms section.

  • Need help to solve update querry for multiple records.

    Could any of you please provide update querry for the following scenario.
    Requiremnt:
    1. Update the UNIQUE_ID of record ( same Identifier and Identifier_code
    where END_Date is not null) with the UNIQUE_ID of the record (( same  Identifier and Identifier_code
    where END_Date  is null).
    2. If More than one NULL in END_date then update UNIQUE_ID with max(EFFective_Date) of UNIQUE_ID
    Source  data
    UNIQUE_ID
    Identifier
    Identifier_code
    EFFective_Date
    END_Date
    1
    777
    abc
    2/14/2014 11:15
    2/28/2014 9:00
    1
    777
    abc
    2/21/2014 9:00
    3/7/2014 9:02
    2
    777
    abc
    2/28/2014 9:00
    3/14/2014 9:02
    2
    777
    abc
    3/7/2014 9:02
    3/14/2014 9:02
    2
    777
    abc
    3/14/2014 9:02
    NULL
    5
    888
    xyz
    2/14/2014 11:15
    2/28/2014 9:00
    5
    888
    xyz
    2/21/2014 9:00
    3/7/2014 9:02
    5
    888
    xyz
    2/28/2014 9:00
    3/14/2014 9:02
    6
    888
    xyz
    3/7/2014 9:02
    NULL
    7
    888
    xyz
    3/14/2014 9:02
    NULL
    OutPUT .
    UNIQUE_ID
    Identifier
    Identifier_code
    EFFective_Date
    END_Date
    2
    777
    abc
    2/14/2014 11:15
    2/28/2014 9:00
    2
    777
    abc
    2/21/2014 9:00
    3/7/2014 9:02
    2
    777
    abc
    2/28/2014 9:00
    3/14/2014 9:02
    2
    777
    abc
    3/7/2014 9:02
    3/14/2014 9:02
    2
    777
    abc
    3/14/2014 9:02
    NULL
    7
    888
    xyz
    2/14/2014 11:15
    2/28/2014 9:00
    7
    888
    xyz
    2/21/2014 9:00
    3/7/2014 9:02
    7
    888
    xyz
    2/28/2014 9:00
    3/14/2014 9:02
    7
    888
    xyz
    3/7/2014 9:02
    NULL
    7
    888
    xyz
    3/14/2014 9:02
    NULL
    Thanks in advance.

    Hi Vikash,
    This query will not produce results as per requirement:
    Try it with following data
    Insert into @TempTABLE values (1,777,'abc','2/14/2014 11:15','3/14/2014 9:02')
    Insert into @TempTABLE values (1,777,'abc','2/21/2014 9:00','3/14/2014 9:02')
    Insert into @TempTABLE values (2,777,'abc','2/28/2014 9:00','3/14/2014 9:02')
    Insert into @TempTABLE values (2,777,'abc','3/7/2014 9:02','3/14/2014 9:02')
    Insert into @TempTABLE values (2,777,'abc','3/14/2014 9:02',NULL)
    Insert into @TempTABLE values (5,888,'xyz','2/14/2014 11:15','3/14/2014 9:02')
    Insert into @TempTABLE values (5,888,'xyz','2/21/2014 9:00','3/14/2014 9:02')
    Insert into @TempTABLE values (5,888,'xyz','2/28/2014 9:00','3/14/2014 9:02')
    Insert into @TempTABLE values (7,888,'xyz','3/7/2014 9:02',NULL)
    Insert into @TempTABLE values (6,888,'xyz','3/14/2014 9:02',NULL)
    as per the problem statement, all records having 888,'xyz' should be updated with 6 not 7 as max effective date is associated with 6 not 7.
    Ashutosh
    Nope.
    can you check the original post first. It clearly states output as having 7 as id for all the records with 888,xyz
    also your above posted sample data is different from original sample data as you've dates jumpled up for the records with ids 6 and 7
    Please see the illustration for original sample data
    --sample table for illustration
    declare @t table
    (UNIQUE_ID int,Identifier int,Identifier_code varchar(100),EFFective_Date datetime ,END_Date datetime)
    --populate original sample data
    INSERT @t ([UNIQUE_ID], [Identifier], [Identifier_code], [EFFective_Date], [END_Date]) VALUES (1, 777, N'abc', CAST(0x0000A2D200B964F0 AS DateTime), CAST(0x0000A2E0009450C0 AS DateTime))
    INSERT @t ([UNIQUE_ID], [Identifier], [Identifier_code], [EFFective_Date], [END_Date]) VALUES (1, 777, N'abc', CAST(0x0000A2D9009450C0 AS DateTime), CAST(0x0000A2E70094DD60 AS DateTime))
    INSERT @t ([UNIQUE_ID], [Identifier], [Identifier_code], [EFFective_Date], [END_Date]) VALUES (2, 777, N'abc', CAST(0x0000A2E0009450C0 AS DateTime), CAST(0x0000A2EE0094DD60 AS DateTime))
    INSERT @t ([UNIQUE_ID], [Identifier], [Identifier_code], [EFFective_Date], [END_Date]) VALUES (2, 777, N'abc', CAST(0x0000A2E70094DD60 AS DateTime), CAST(0x0000A2EE0094DD60 AS DateTime))
    INSERT @t ([UNIQUE_ID], [Identifier], [Identifier_code], [EFFective_Date], [END_Date]) VALUES (2, 777, N'abc', CAST(0x0000A2EE0094DD60 AS DateTime), NULL)
    INSERT @t ([UNIQUE_ID], [Identifier], [Identifier_code], [EFFective_Date], [END_Date]) VALUES (5, 888, N'xyz', CAST(0x0000A2D200B964F0 AS DateTime), CAST(0x0000A2E0009450C0 AS DateTime))
    INSERT @t ([UNIQUE_ID], [Identifier], [Identifier_code], [EFFective_Date], [END_Date]) VALUES (5, 888, N'xyz', CAST(0x0000A2D9009450C0 AS DateTime), CAST(0x0000A2E70094DD60 AS DateTime))
    INSERT @t ([UNIQUE_ID], [Identifier], [Identifier_code], [EFFective_Date], [END_Date]) VALUES (5, 888, N'xyz', CAST(0x0000A2E0009450C0 AS DateTime), CAST(0x0000A2EE0094DD60 AS DateTime))
    INSERT @t ([UNIQUE_ID], [Identifier], [Identifier_code], [EFFective_Date], [END_Date]) VALUES (6, 888, N'xyz', CAST(0x0000A2E70094DD60 AS DateTime), NULL)
    INSERT @t ([UNIQUE_ID], [Identifier], [Identifier_code], [EFFective_Date], [END_Date]) VALUES (7, 888, N'xyz', CAST(0x0000A2EE0094DD60 AS DateTime), NULL)
    --do the update
    UPDATE t
    SET UNIQUE_ID = MaxID
    FROM
    SELECT MAX(CASE WHEN END_DATE IS NULL THEN UNIQUE_ID END) OVER (PARTITION BY Identifier,Identifier_code) AS MaxID,UNIQUE_ID
    FROM @t
    )t
    WHERE UNIQUE_ID <> MaxID
    AND MaxID IS NOT NULL
    --now check the output
    SELECT * FROM @t
    The output is as below
    UNIQUE_ID Identifier Identifier_code EFFective_Date END_Date
    2 777 abc 2014-02-14 11:15:00.000 2014-02-28 09:00:00.000
    2 777 abc 2014-02-21 09:00:00.000 2014-03-07 09:02:00.000
    2 777 abc 2014-02-28 09:00:00.000 2014-03-14 09:02:00.000
    2 777 abc 2014-03-07 09:02:00.000 2014-03-14 09:02:00.000
    2 777 abc 2014-03-14 09:02:00.000 NULL
    7 888 xyz 2014-02-14 11:15:00.000 2014-02-28 09:00:00.000
    7 888 xyz 2014-02-21 09:00:00.000 2014-03-07 09:02:00.000
    7 888 xyz 2014-02-28 09:00:00.000 2014-03-14 09:02:00.000
    7 888 xyz 2014-03-07 09:02:00.000 NULL
    7 888 xyz 2014-03-14 09:02:00.000 NULL
    Now compare it with original output and you'll find they're the same
    UNIQUE_ID Identifier Identifier_code EFFective_Date END_Date
    2 777 abc 2/14/2014 11:15 2/28/2014 9:00
    2 777 abc 2/21/2014 9:00 3/7/2014 9:02
    2 777 abc 2/28/2014 9:00 3/14/2014 9:02
    2 777 abc 3/7/2014 9:02 3/14/2014 9:02
    2 777 abc 3/14/2014 9:02 NULL
    7 888 xyz 2/14/2014 11:15 2/28/2014 9:00
    7 888 xyz 2/21/2014 9:00 3/7/2014 9:02
    7 888 xyz 2/28/2014 9:00 3/14/2014 9:02
    7 888 xyz 3/7/2014 9:02 NULL
    7 888 xyz 3/14/2014 9:02 NULL
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Use of LIKE in where clause of select statement for multiple records

    Hi Experts,
    I have a account number field which is uploaded from a file. Now this account numbers uploaded does not match fully with sap table account numbers but it contains all of the numbers provided in the file mostly in the upright positions.
    For example in file we have account number as 2ARS1 while in sap table the value is 002ARS1.
    And i want to fetch data from sap table based on account number uploaded. So, i am trying to use LIKE with for all entries but its not working as mentioned below but LIKE is not working with FOR ALL ENTRIES.
    data : begin of t_dda occurs 0,
            dda(19) type c,
           end of t_dda.
    data : begin of t_bukrs occurs 0,
            bukrs type t012k-bukrs,
           end of t_bukrs.
    data : dda type t012k-bankn,
           w_dda type t012k-bankn.
    CONCATENATE '%'
                             '2ARS1'
                     INTO  W_DDA.
    MOVE W_DDA TO T_DDA-DDA.
    APPEND T_DDA.
    CLEAR T_DDA.
    free t_bukrs.
    SELECT BUKRS
      FROM T012K
      into TABLE t_bukrs
        for all entries in t_dda
    WHERE BANKN like t_dda-dda.
    Can anybody suggest what should i use to get the data for multiple account numbers using one select statement only instead on using SELECT UP TO 1 ROWS in LOOP....ENDLOOP ?
    Thanks in advance,
    Akash

    Hi,
    yes, For All entries won't work for LIKE with '%  '.
    I think the other alternative is go for Native SQL by writing sub-query
    sample code is here:
    data: begin of i_mara occurs 0,
              matnr like mara-matnr,
              matkl like mara-matkl,
           end of i_mara.
    exec sql.
    select matnr, matkl from mara where matnr in (select matnr from marc) and matnr like '%ma' into :i_mara
    endexec.
    loop at i_mara.
    write:/ i_mara-matnr, i_mara-matkl.
    endloop.
    hope u got it.
    regards
    Mahesh
    Edited by: Mahesh Reddy on Jan 21, 2009 2:32 PM

  • Update statement for object table.

    Hi,
    I have created one type as
    Create type test as object(
    ins_by varchar2(30),
    ins_on date,
    upd_by varchar2( 30),
    upd_on date);
    and then created an object table as
    create table imst(
    i_code number(5),
    i_desc varchar2(35),
    i_op test);
    now i am able to insert record in this table as
    insert into imst values(1,'Hawkins cooker',test(user,sysdate,'',''));
    Above works fine.
    But I would also like to update the record with i_op.upd_by,i_op.upd_on with some other values.
    Can any body help me specifying how to write a plain update statement for the same.
    Regards.
    Soumen

    Check it out:
    SQL> Create type myTest as object(
      2  ins_by varchar2(30),
      3  ins_on date,
      4  upd_by varchar2( 30),
      5  upd_on date);
      6  /
    Type created.
    SQL> create table imst(
      2  i_code number(5),
      3  i_desc varchar2(35),
      4  i_op myTest);
    Table created.
    SQL> insert into imst values(1,'Hawkins cooker', mytest(user,sysdate,'',''));
    1 row created.
    SQL> select * from imst;
        I_CODE I_DESC
    I_OP(INS_BY, INS_ON, UPD_BY, UPD_ON)
             1 Hawkins cooker
    MYTEST('APC_LOAD', '12-JUL-04', NULL, NULL)
    SQL> update imst i set i.i_op.upd_by = USER, i.i_op.upd_on = add_months(sysdate, 1);
    1 row updated.
    SQL> select * from imst;
        I_CODE I_DESC
    I_OP(INS_BY, INS_ON, UPD_BY, UPD_ON)
             1 Hawkins cooker
    MYTEST('APC_LOAD', '12-JUL-04', 'APC_LOAD', '12-AUG-04')
    SQL> Smoke me a kipper I'll be back before breakfast.
    Cheers, APC

  • Update stats for table in dbstatc

    Hello all,
        I am very new to administrating SAP on Oracle.  My question is.  There are some tables in dbstatc with ignore flag.  I ran the below query to get that...
    select COUNT(*) from sapsr3.dbstatc
    where ACTIV = 'I';
    Now from my understanding the I flag means...do not update stats for that table...
    So i first ran below...which runs the full stats and it did not update or touched those table in dbstats with I flag
    brconnect -c -u / -f stats -t all -f collect -p 8
    so after researching i found we can update those stats with below .... even after running the below, stats still do not show up as update.... how can i update (forcefully if required) to update stats for a particular table....
    brconnect -u / -c -f stats -t SAPSR3.table_name -f allsel -p 4          
    i query dba_tables at DB level to see if that specific table was analyzed or not.  I am on 11.2 oracle version...and this is a BW SAP system....

    New User:
    1)  Which objects do you have the INACTIVE flag set for:
    col dbobj format a20
    select dbobj, activ from sapsr3.dbstatc where activ = 'I' order by 1;
    2)  Check that you have the correct DBSTATC settings per SAP Note 403704.
    If you do not, then I would suggest you update the DBSTATC table following SAP Note 403704, but before you do take a copy of the dbstatc table:
    sqlplus sapsr3/<pass.
    create table dbstatc_old as select * from dbstatc;
    3)  To check to see if you have stats on a table:
    select table_name, partitioned, last_analyzed, num_rows from dba_tables where table_name = 'TBTCO';
    TABLE_NAME                     PAR LAST_ANALYZED     NUM_ROWS
    TBTCO                          NO  19-MAY-11           163030
    If the LAST_ANALYZED shows up with NO values, then there are NO stats on the table.
    HOWEVER, be careful for partitioned tables in BW because there are stats at the partition level as well:
    select TABLE_NAME, PARTITION_NAME, LAST_ANALYZED, NUM_ROWS from dba_tab_partitions where table_name = '<table>';
    4)  To collect the statistics on a table
    brconnect -c -u / -f stats -t <TABLE> -f allsel,collect -g 4 -p 16
    5)  If the stats are still not collected with the brconnect command, it may be because the stats are locked at the table level from SAP Note 1020260:
    SELECT stattype_locked FROM dba_tab_statistics WHERE table_name = '<TABLE>';
    If the value is ALL, then the stats may be locked at the table level and may require to unlock the stats before updating.
    Good Luck,
    Mike Kennedy

  • 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.

  • Master data update bringing in multiple records for single entry

    Hello,
    I found that if I deleted and reloaded data in a master data object, it was showing me correct number of records. However, just a full update was not overwriting it with correct number of data records. there were always 1 or 2 extra blank records. I thought master data update should overwrite previous records and we need not delete and reload it.
    Why would this happen?
    Thanks!

    Hi there,
    Are you refering to time dependent master data? From to values are present?
    If so, that's the correct situation, since BW (OLAP) instead of R/3 (OLTP) allows you to mantain historical data, i.e., a material can be valid from a specific time period with several attributes and other attributes can be valid for the same material in another time space.
    Diogo.

  • Updation/insertion of multiple records simultaneously using check box

    Hi,
    I am using Jdev11.1.1.2.0 version. I have the following scenario.
    There is a table in the view.At run time, I need to select multiple records and update those records in the database. So i took check Box as a column in the table.*(I did not associate check box to any of the attributes (columns) in the table.)* After running the application, I selected multiple records using checkbox and submitting them. The check box is returning value as 'false' even for the selected records also instead of 'true'. Because of this we are facing the issue in updating only the selected records. Please suggest your valuable inputs.
    I have written the following code in the backing bean to get the selected rows.
    BindingContainer bindings =BindingContext.getCurrent().getCurrentBindingsEntry();
    DCIteratorBinding dcIter= (DCIteratorBinding) bindings.get("PttDeliverabvleTrackerEOView2Iterator");
    RowSetIterator depRSIter = dcIter.getRowSetIterator();
    depRSIter.setRangeSize(depRSIter.getRowCount());
    Integer key = depRSIter.getRowCount();
    System.out.println("No of rows is "+ key);
    int rowIndex =0;
    for(int i =0; i<key; i++){
    PttDeliverabvleTrackerEOViewRowImpl row = (PttDeliverabvleTrackerEOViewRowImpl) depRSIter.getRowAtRangeIndex(i);
    System.out.println("Check box value2 "+ this.getSbc1().isSelected());
    if(this.getSbc1().isSelected()){
    rowIndex = i;
    System.out.println("Row Index: "+ rowIndex);
    Please let me know if it is it possible to associate a checkbox to any of the attributes while dragging and dropping the table in the view and update the records?
    I tried selecting the option 'Row Selection' while dragging and dropping the table and changed the property RowSelection->multiple. But it is not serving the purpose of updating multiple records.
    Please suggest if there is any other solution to update multiple records.
    Regards,
    Sreelatha.

    Hi,
    if you added checkboxes to a table, then at runtime the checkbox is stamped, which means that a call to this.getSbc1().isSelected() just returns the state of the last checkbox that is rendered. I don't want to go into the details of ADF Faces table rendering here, but point yu to a blog article that does what you are aiming for using ADF BC: http://sameh-nassar.blogspot.com/2009/12/use-checkbox-for-selecting-multiple.html
    Frank

  • Updating status of multiple records after saving the form

    Hi all
    I have a tabular form
    It has a column status (new,good ,very good ,excellent are the list options)
    The user goes and modifies a number of records on the detail block and saves the records
    what i want to do is that when the user clicks the save button after updating any number of records
    the status field should be updated with the value (new)
    the status field of those records should be updated with the new value which the user has modified not all the records
    Please let me know how to go about it
    thanks
    Edited by: bindok mulga on May 11, 2009 3:48 PM
    Edited by: bindok mulga on May 11, 2009 3:50 PM

    Hi
    actually my earlier post was incorrect
    i have edited my post
    Actually
    i want to update only those records that the user has modified
    eg
    col1 col2 status
    1 ABC good
    2 PQR good
    3 xyz good
    4 lmn excellent
    5 abcz excellent
    is the table before the user modifies
    the user goes and modifies multiple records as following
    col1 col2 status
    1 aaa good
    2 PQR good
    3 xxx good
    4 sss excellent
    5 abcz excellent
    and the user saves the form
    now i want the following output
    col1 col2 status
    1 aaa new
    2 PQR good
    3 xxx new
    4 sss new
    5 abcz excellent
    only the modified record's status should be updated
    sorry for the earlier lapse

  • Convert a SQL Server Update Statement for Oracle

    Hi,
    i need to convert an update statement written for SQL Server to make it work on Oracle,
    the update is the following:
    UPDATE     TABLE1
    SET     CDate = TBL2.CDate
    FROM      TABLE1 TBL1
              JOIN TABLE2 TBL2 ON TBL2.Code = TBL1.TBL2Code
              JOIN TABLE3 TBL3 ON TBL3.Id = TBL1.Id
    WHERE     TBL3.TypeCode = '07'
    how can i make it compatible with oracle?
    thanks!!

    Billy  Verreynne  wrote:
    Karthick_Arp wrote:
    Try this
    <snipped>Dislike such an approach that requires multiple hits on the same tables. This is never scalable. A key performance issue is to do only one pass through a data set when possible and not do multiple passes.Yes i understand. But to do a update on a join the table must be a Key Preserved Table. And for a normal Update it is necessory to have an EXISTS clause so that we dont update the non-matching rows to NULL.

  • How to tune the Update statement for 20 million rows

    Hi,
    I want to update 20 million rows of a table. I wrote the PL/SQL code like this:
    DECLARE
    v1
    v2
    cursor C1 is
    select ....
    BEGIN
    Open C1;
    loop
    fetch C1 bulk collect into v1,v2 LIMIT 1000
    exit when C1%NOTFOUND;
    forall i in v1.first..v1.last
    update /*+INDEX(tab indx)*/....
    end loop;
    commit;
    close C1;
    END;
    The above code took 24 mins to update 100k records, so for around 20 million records it will take 4800 mins (80 hrs).
    How can I tune the code further ? Will a simple Update statement, instead of PL/SQL make the update faster ?
    Will adding few more hints help ?
    Thanks for your suggestions.
    Regards,
    Yogini Joshi

    Hello
    You have implemented this update in the slowest possible way. Cursor FOR loops should be absolute last resort. If you post the SQL in your cursor there is a very good chance we can re-code it to be a single update statement with a subquery which will be the fastest possible way to run this. Please remember to use the {noformat}{noformat} tags before and after your code so the formatting is preserved.
    David                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Enforcement States for multiple deployment ID's

    I would like to have a report for the enforcement states of multiple deployment ID's. I have tried manipulating the default "States 1 - Enforcement states for a deployment" to have multiple default values but have not succeeded in getting
    the report to run.
    In our Software Updates we have multiple collections targeting specific groups of computers and then we have specific update groups within specific date ranges deployed to those collections. In some cases I have multiple deployments targeting the same collection
    and thus the want to have a single report for the enforcement status of multiple deployment ID's.
    Unfortunatley my level of SQL reporting is minimal, does anyone have knowledge of a report or query to use multiple deployment ID's for returning the enforcement states?

    Hi,
    You may have a look on the following blog, hope this could help you edit your report.
    http://blogs.msdn.com/b/steverac/archive/2013/01/13/modifying-a-report-to-merge-software-update-deployments-with-updates-delivered-through-standard-software-distribution.aspx
    Best Regards,
    Joyce
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • Scheduled Job to gather stats for multiple tables - Oracle 11.2.0.1.0

    Hi,
    My Oracle DB Version is:
    BANNER Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE 11.2.0.1.0 Production
    TNS for Linux: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    In our application, we have users uploading files resulting in insert of records into a table. file could contain records ranging from 10000 to 1 million records.
    I have written a procedure to bulk insert these records into this table using limit clause. After the insert, i noticed my queries run slow against these tables if huge files are uploaded simultaneously. After gathering stats, the cost reduces and the queries executed faster.
    We have 2 such tables which grow based on user file uploads. I would like to schedule a job to gather stats during a non peak hour apart from the nightly automated oracle job for these two tables.
    Is there a better way to do this?
    I plan to execute the below procedure as a scheduled job using DBMS_SCHEDULER.
    --Procedure
    create or replace
    PROCEDURE p_manual_gather_table_stats AS
    TYPE ttab
    IS
        TABLE OF VARCHAR2(30) INDEX BY PLS_INTEGER;
        ltab ttab;
    BEGIN
        ltab(1) := 'TAB1';
        ltab(2) := 'TAB2';
        FOR i IN ltab.first .. ltab.last
        LOOP
            dbms_stats.gather_table_stats(ownname => USER, tabname => ltab(i) , estimate_percent => dbms_stats.auto_sample_size,
            method_opt => 'for all indexed columns size auto', degree =>
            dbms_stats.auto_degree ,CASCADE => TRUE );
        END LOOP;
    END p_manual_gather_table_stats;
    --Scheduled Job
    BEGIN
        -- Job defined entirely by the CREATE JOB procedure.
        DBMS_SCHEDULER.create_job ( job_name => 'MANUAL_GATHER_TABLE_STATS',
        job_type => 'PLSQL_BLOCK',
        job_action => 'BEGIN p_manual_gather_table_stats; END;',
        start_date => SYSTIMESTAMP,
        repeat_interval => 'FREQ=DAILY; BYHOUR=12;BYMINUTE=45;BYSECOND=0',
        end_date => NULL,
        enabled => TRUE,
        comments => 'Job to manually gather stats for tables: TAB1,TAB2. Runs at 12:45 Daily.');
    END;Thanks,
    Somiya

    The question was, is there a better way, and you partly answered it.
    Somiya, you have to be sure the queries have appropriate statistics when the queries are being run. In addition, if the queries are being run while data is being loaded, that is going to slow things down regardless, for several possible reasons, such as resource contention, inappropriate statistics, and having to maintain a read consistent view for each query.
    The default collection job decides for each table based on changes it perceives in the data. You probably don't want the default collection job to deal with those tables. You probably do want to do what Dan suggested with the statistics. But it's hard to tell from your description. Is the data volume and distribution volatile? You surely want representative statistics available when each query is started. You may want to use all the plan stability features available to tell the optimizer to do the right thing (see for example http://jonathanlewis.wordpress.com/2011/01/12/fake-baselines/ ). You may want to just give up and use dynamic sampling, I don't know, entire books, blogs and papers have been written on the subject. It's sufficiently advanced technology to appear as magic.

Maybe you are looking for

  • How to config status in Search in T-code : cic0

    Dear All We just upgrade from CRM 2.0c to CRM 5.0 . How to config status in Search in T-code : cic0, because the status in the Search transaction, is different from the Activity transaction . Please help. Thank and best regards, Vimol

  • How to set up outgoing mail on iphone 3gs

    im new at this  can you tell me how to set up outgoing mail from my iphone

  • Installing iTunes 10.3 and removing older version of Bonjour error

    I'm trying to install iTunes version 10.3 on my laptop.  During the installation an error message occurs "The older version of Bonjour cannot be removed. Contact your technical support group."  At the end of the installation process another message o

  • Booting into safe mode

    We have just acquired a sparcstation 4, but have not got a Sun monitor to use it with. We can't set it up because we can't see anything to set it up!! Does anyone know a keyboard shortcut to boot into safe mode so that we can get started with it? We

  • SCSM Server freezes unexpectedly

    I have been struggling with this issue for two weeks, and i couldn't find any reasonable answer for my problem. We have SCSM server 2012 running on a very powerful blade server together with the database. The hardware specs is surely more than we nee