Update statement query

I have a peculiar problem related to update statement.
In a table "table1" I have the following values for the column Name.
John
Doe
Adam
Teela
I need to do the following updates
John -> Adam
Doe -> Teela
Adam -> Doe
Teela -> John
One way of doing it would be to use the ROWID.
Update table1 set value=Adam where ROWID=1
Update table1 set value=Teela where ROWID=2
and so on and so forth.
But I don't want to use the ROWID.
Therefore the logical query that one would write is
Update table1 set value=Adam where value=John
Update table1 set value=Teela where value=Doe
Update table1 set value=Doe where value=Adam
Update table1 set value=John where value=Teela
But immediately the problem becomes apparent.
The converted table would now look like this
Doe
John
Doe
John
How do I make sure that the updation happens as I intend? Is there a way to work around it without ROWID?
Message was edited by:
user574608

Much too late, but I don't want to have made it in vain ;) :
michaels>  CREATE TABLE table1 (ID INTEGER,VALUE VARCHAR2(10))
Table created.
michaels>  INSERT INTO table1
     VALUES (1, 'John')
1 row created.
michaels>  INSERT INTO table1
     VALUES (2, 'Doe')
1 row created.
michaels>  INSERT INTO table1
     VALUES (3, 'Adam')
1 row created.
michaels>  INSERT INTO table1
     VALUES (4, 'Teela')
1 row created.
michaels>  UPDATE table1
   SET VALUE =
          CASE VALUE
             WHEN 'John'
                THEN 'Adam'
             WHEN 'Doe'
                THEN 'Teela'
             WHEN 'Adam'
                THEN 'Doe'
             WHEN 'Teela'
                THEN 'John'
          END
4 rows updated.
michaels>  SELECT *
  FROM table1
        ID VALUE    
         1 Adam     
         2 Teela    
         3 Doe      
         4 John     
4 rows selected.

Similar Messages

  • Help with doing SELECT sub query within the SET of an UPDATE statement

    After doing some research, it appears as if it's possible to use a SELECT subquery in the SET of an UPDATE statement.  i did find some examples and here is my code, however when I click the "check" button it's saying the field (my entire select subquery) is unknown and neither in one of the specified tables or defined by a "DATA".  Do I have a syntax issue or is there another reason why it's not taking this as a valid statement?  Thanks for the help!
    LOOP AT IT_DATA
    UPDATE /BIC/AZDP_O0140
       SET /BIC/ZCOUNTER = (SELECT COUNT( DISTINCT MATERIAL )
                            FROM /BIC/AZDP_O0140
                            WHERE MATERIAL EQ IT_DATA-MATERIAL
                            GROUP BY MATERIAL).
    ENDLOOP.

    my Update does indeed have a WHERE clause but because of the issue i'm having, all my criteria in my WHERE is black text in the ABAP editor.  The editor doesn't even recognize the keywords "WHERE" or "EQ".  Below is my entire statement which contains all WHERE criteria in both the Update and the Subquery, i've just removed it for testing to help simplify the query and eliminate as many other factors as posisble that may be causing problems:
    LOOP AT IT_DATA.
       UPDATE /BIC/AZDP_O0140
       SET /BIC/ZCOUNTER = (SELECT COUNT( DISTINCT MATERIAL ) FROM /BIC/AZDP_O0140
       WHERE WHSE_NUM EQ IT_DATA-WAREHOUSE
        AND  PLANT EQ IT_DATA-PLANT
        AND  /BIC/ZTRAN_NO EQ IT_DATA-TRANS_NUM
        AND  DELIV_NUMB EQ IT_DATA-DELIVERY
        AND  MATERIAL EQ IT_DATA-MATERIAL
        GROUP BY MATERIAL)
       WHERE WHSE_NUM EQ IT_DATA-WAREHOUSE
        AND  PLANT EQ IT_DATA-PLANT
        AND  /BIC/ZTRAN_NO EQ IT_DATA-TRANS_NUM
        AND  DELIV_NUMB EQ IT_DATA-DELIVERY
        AND  MATERIAL EQ IT_DATA-MATERIAL.
    ENDLOOP.
    i should also mention the sources i found were not within the SAP Library but instead on other third-party ABAP websites.  so because i was having issues i wanted to post here to see if anyone else has come up with a working solution.  but if this cannot be done i can likely come up with a solution for my needs using multiple internal tables, this would just have been much easier since i can get a query like this to do what i want in SQL Server.  Thought i could utilize this in ABAP as well.

  • Update Statement with group by query

    I need to an update statement that updates the records return from this query:
    SELECT
    GROUP,
    SECTION,
    MAX(ASSIGNED_DATE)
    FROM
    ASSIGNMENTS
    GROUP BY GROUP, SECTION
    I need to update all those records and set HISTORY = 1
    I'm not sure how to form the update statement.
    UPDATE ASSIGNMENTS SET HISTORY = 1 WHERE (SELECT
    GROUP,
    SECTION,
    MAX(ASSIGNED_DATE)
    FROM
    ASSIGNMENTS
    GROUP BY GROUP, SECTION) ?
    Edited by: user9179751 on Apr 18, 2011 11:23 AM

    Just doing a select query: (these are the records that were updated when I ran the update statement you posted)
    SELECT * FROM ASSIGNMENS WHERE (GROUP, SECTION, ASSIGNED_DATE) IN (SELECT GROUP,
    SECTION, MAX(ASSIGNED_DATE)FROM ASSIGNMENTS GROUP BY GROUP, SECTION)
    Records:
    GROUP SECTION    ASSIGNED_DATE
    0010        050098       20011108
    0334    000003       19980116
    0505        320000       20000712
    0676        380000       19980914
    0676        067931       20011221
    0801        600500       19910409
    0801    601701       20090903These are the records I want updated:
    Which I would get using:
    SELECT GROUP, SECTION, MAX(ASSIGNED_DATE)FROM ASSIGNMENTS GROUP BY GROUP, SECTION
    GROUP SECTION ASSIGNED_DATE
    0002                  20100519
    0003                  20090724
    0005          
    0007       360000     
    0007                  20040913
    0009                  19970814
    0010       050098     20011108
    0010                  20000926
    0011          I'm assuming it skips over null values?

  • UPDATE statement based on query and return multiple value

    Hi everybody,
    I have two tables: temp3 and temp
    One of them (temp3) should be updated based on the query where clause (id and flag columns).
    I run this query but it updates all of the records in the temp3. I want to update only records with 'UPDATED' flag.
    update temp3 t3
    set (id,name,address) = (select t.id, t.name, t.address from temp t, temp3 t3
    where t.id = t3.id and t.flag = 'UPDATED');
    Does any body know how I can do it?
    I appreciate your help
    Thx

    Hello
    Basically you're missing a where clause on your update statement to restrict rows in t3 to the ones that have a corresponding row in t1.
    SQL> select * from dt_test_t1;
            ID NAME                 ADDRESS              ROW_STATUS
             1 Joseph Bloggs        Some street          UPDATED
             1 Joe Bloggs           Old street           OLD
             2 Fredrick Bloggs      New street           UPDATED
             2 Fred Bloggs          Some street          OLD
             3 Robert Bloggs        Better street        UPDATED
             3 Bob Bloggs           Some street          OLD
           100 Barry Bethel         Some street          UPDATED
           200 Giles Brandreth      Some street          UPDATED
    8 rows selected.
    SQL> select * from dt_test_t3;
            ID NAME                 ADDRESS              ROW_STATUS
             1 Joe Bloggs           Old street
             2 Fred Bloggs          Some street
             3 Bob Bloggs           Some street
             4 Joe Smith            Some street
             5 John Doe             Some street
    --this update as it stands does not work as it updates rows to have
    --null name and address where there is not a proper matching row in
    --t1
    SQL> UPDATE
      2     dt_test_t3 t3
      3  SET
      4     (       t3.name,
      5             t3.address,
      6             t3.row_status
      7     ) = (SELECT
      8             t1.name,
      9             t1.address,
    10             t1.row_status
    11          FROM
    12             dt_test_t1 t1
    13          WHERE
    14             t1.id = t3.id
    15          AND
    16             t1.row_status = 'UPDATED'
    17         );
    5 rows updated.
    SQL> select * from dt_test_t3;
            ID NAME                 ADDRESS              ROW_STATUS
             1 Joseph Bloggs        Some street          UPDATED
             2 Fredrick Bloggs      New street           UPDATED
             3 Robert Bloggs        Better street        UPDATED
    4
    5
    SQL> rollback;
    Rollback complete.
    --Now add in the where clause to make sure we're only updating rows in
    --t3 that have a corresponding row in t1:
    SQL> UPDATE
      2     dt_test_t3 t3
      3  SET
      4     (       t3.name,
      5             t3.address,
      6             t3.row_status
      7     ) = (SELECT
      8             t1.name,
      9             t1.address,
    10             t1.row_status
    11          FROM
    12             dt_test_t1 t1
    13          WHERE
    14             t1.id = t3.id
    15          AND
    16             t1.row_status = 'UPDATED'
    17         )
    18  WHERE
    19     EXISTS( SELECT
    20                     NULL
    21             FROM
    22                     dt_test_t1 t1
    23             WHERE
    24                     t1.id = t3.id
    25             AND
    26                     t1.row_status = 'UPDATED'
    27             );
    3 rows updated.
    SQL> select * from dt_test_t3;
            ID NAME                 ADDRESS              ROW_STATUS
             1 Joseph Bloggs        Some street          UPDATED
             2 Fredrick Bloggs      New street           UPDATED
             3 Robert Bloggs        Better street        UPDATED
             4 Joe Smith            Some street
             5 John Doe             Some streetHTH
    David

  • Need help to write a query for Update statement with  join

    Hi there,
    The following update statement gives me error as the given table in set statement is invalid. But its the right table .
    Is the statement correct? Please help .
    update (
           select distinct(vpproadside.VEHICLE_CRED_OVERRIDE.vin)            
             from vpproadside.VEHICLE_CRED_OVERRIDE
             join vpproadside.vpp_vehicle
               on vpproadside.vpp_vehicle.vin = vpproadside.VEHICLE_CRED_OVERRIDE.vin
            where VPP_CARRIER_SEQ_NUMBER = 90
              and EXPIRY_DATE = '17-MAR-10'
       set vpproadside.VEHICLE_CRED_OVERRIDE.EXPIRY_DATE = '15-SEP-10';Edited by: Indhu Ram on Mar 12, 2010 1:00 PM
    Edited by: Indhu Ram on Mar 12, 2010 1:22 PM
    Edited by: Indhu Ram on Mar 12, 2010 2:35 PM
    Edited by: Indhu Ram on Mar 15, 2010 8:04 AM
    Edited by: Indhu Ram on Mar 15, 2010 8:06 AM
    Edited by: Indhu Ram on Mar 15, 2010 8:28 AM

    Ask Tom has very good discussion about this, if UPDATE does not work for PK issue, you can use MERGE
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:760068400346785797

  • Decode function in Update statement

    Hello everyone,
    I'm trying to write a query where I can update a pastdue_fees column in a book_trans table based on a difference between return_dte and due_dte columns.
    I am using Oracle SQL. This is what I have so far for my decode function:
    SQL> SELECT
    2 DECODE(SIGN((return_dte - due_dte)*2),
    3 '-1', '0',
    4 '1', '12', 'Null')
    5 FROM book_trans;
    DECO
    Null
    12
    Null
    0
    So the logic is that if the sign is -1, the value in return_dte column should be 0; if it's +1 then it's 12 and everything else is Null.
    So now, I need to enter my decode function into the update statement to update the columns. However, I get error messages.
    The logic should be:
    UPDATE book_trans SET PastDue_fees = decode(expression)
    I've given it a couple of different tries with the following results:
    SQL> UPDATE book_trans
    2 SET pastdue_fees = SELECT
    3 DECODE(SIGN((return_dte - due_dte)*2),
    4 '-1', '0',
    5 '1', '12', 'Null')
    6 FROM book_trans;
    SET pastdue_fees = SELECT
    ERROR at line 2:
    ORA-00936: missing expression
    SQL> UPDATE book_trans
    2 SET pastdue_fees =
    3 DECODE(SIGN((return_dte - due_dte)*2),
    4 '-1', '0',
    5 '1', '12', 'Null')
    6 FROM book_trans;
    FROM book_trans
    ERROR at line 6:
    ORA-00933: SQL command not properly ended
    Any help or tips would be greatly appreciated as I've been taking SQL for about six weeks and not very proficient!
    Thanks!

    882300 wrote:
    Hello everyone,
    I'm trying to write a query where I can update a pastdue_fees column in a book_trans table based on a difference between return_dte and due_dte columns.
    I am using Oracle SQL. This is what I have so far for my decode function:
    SQL> SELECT
    2 DECODE(SIGN((return_dte - due_dte)*2),
    3 '-1', '0',
    4 '1', '12', 'Null')
    5 FROM book_trans;
    DECO
    Null
    12
    Null
    0
    So the logic is that if the sign is -1, the value in return_dte column should be 0; if it's +1 then it's 12 and everything else is Null.
    So now, I need to enter my decode function into the update statement to update the columns. However, I get error messages.
    The logic should be:
    UPDATE book_trans SET PastDue_fees = decode(expression)
    I've given it a couple of different tries with the following results:
    SQL> UPDATE book_trans
    2 SET pastdue_fees = SELECT
    3 DECODE(SIGN((return_dte - due_dte)*2),
    4 '-1', '0',
    5 '1', '12', 'Null')
    6 FROM book_trans;
    SET pastdue_fees = SELECT
    ERROR at line 2:
    ORA-00936: missing expression
    SQL> UPDATE book_trans
    2 SET pastdue_fees =
    3 DECODE(SIGN((return_dte - due_dte)*2),
    4 '-1', '0',
    5 '1', '12', 'Null')
    6 FROM book_trans;
    FROM book_trans
    ERROR at line 6:
    ORA-00933: SQL command not properly ended
    Any help or tips would be greatly appreciated as I've been taking SQL for about six weeks and not very proficient!
    Thanks!If you really really really want to update the entire table, the syntax would be...
    UPDATE book_trans
       SET
          pastdue_fees  = DECODE(SIGN((return_dte - due_dte)*2), -1, 0, 1, 12, Null);I took out all the single quotes. If you actually have a string column and you're storing entirely numbers in it then it should be declared as a NUMBER column and not a character (varchar2) column.
    ALWAYS use the proper data type, it'll save you a ton of headaches in the future.
    Also, since you're new to the forum, please read the FAQ so you learn the etiquette and what not.
    http://wikis.sun.com/display/Forums/Forums+FAQ

  • Running an update statement on two dependent attributes

    Dear All,
    I have a repair_job table that contains values for work_cost, parts_cost and total_cost which is the sum of the work and parts cost values. I want to run an update statement that doubles the work cost and, naturally, updates the value of total cost as well. I tried to run it as:
    update repair_job
    set work_cost = 2 * work_cost, total_cost = work_cost + parts_cost
    where licence in (
    select licence from car
    where year = to_char(sysdate,'YYYY')
    thinking that because the update of work_cost is first on the list, the updated value of total cost would be correct. It seems however that the update of total cost happens first and then the work cost is been updated; not sure what the reason is for that and it happens no matter what the order is in the update statement.
    I know that I can do it in two separate statements, or use a trigger or PL/SQL to do it but I am curious as to why it has this behaviour. Also, is there a way to do it in a single SQL statement - i.e. forcing the update of the work_cost attribute first and then that of total_cost?
    I look forward to hearing from you soon.
    Regards,
    George

    Welcome to the forum!
    >
    thinking that because the update of work_cost is first on the list, the updated value of total cost would be correct. It seems however that the update of total cost happens first and then the work cost is been updated; not sure what the reason is for that and it happens no matter what the order is in the update statement.
    I know that I can do it in two separate statements, or use a trigger or PL/SQL to do it but I am curious as to why it has this behaviour. Also, is there a way to do it in a single SQL statement - i.e. forcing the update of the work_cost attribute first and then that of total_cost?
    >
    The update to all columns of the row happen at the same time - there is no order involved.
    You don't need two statements but you do need to do the updates based on the current value of the columns.
    set work_cost = 2 * work_cost, total_cost = 2 * work_cost + parts_cost----------
    In addition to sb92075's comments in 11 g you could also just define a virtual column for total_cost and then just query it like you do now.
    total_cost   NUMBER GENERATED ALWAYS AS (work_cost + parts_cost) VIRTUAL,See this Oracle-base article for an example
    http://www.oracle-base.com/articles/11g/virtual-columns-11gr1.php
    Edited to supplement sb92075's reply by mentioning virtual columns

  • Update statement getting ORA-00904 invalid identifier

    I am getting this ORA error when I try to conduct an update statement from a column value in one table to a like-named column in another table.
    For instance, in my select, shown below, this query runs like a champ, returning all of my records
    SELECT
    b.ID,
    b.ZIP, a.ZIP,
    a.NAME,
    a.LOCATION
    FROM TBL_ARCHIVE a
    INNER JOIN TBL_UAT b ON
    a.ID = b.ID
    WHERE
    b.ID > 470000  And b.ID <470100;However, if I try to run an update statement with any of the following, I get this error. It seems so strange to me that I'd get an error using the same columns in the update statement, but would return the desired results effectively from the select statement!
    one version of UPDATE
    UPDATE TBL_ARCHIVE a
    SET a.ZIP = TBL_UAT.ZIP
    WHERE TBL_UAT.ID = a.ID;and another
    UPDATE TBL_ARCHIVE
    SET a.ZIP  =
    (SELECT b.ZIP
    FROM TBL_UAT b
    WHERE b.ID <472500 And b.ID >471000)
    FROM TBL_ARCHIVE a
    WHERE a.ID = b.ID)
    WHERE ID IN
    (SELECT ID
    FROM TBL_UAT b
    WHERE b.ID  <472500 And b.ID >471000
    );^ - this one produces a SQL not properly ended. Error ORA-00933: SQL command not properly ended.
    I'm really unsure though, how what I thought was a fairly basic update statement wouldn't work. I'm using Oracle 11g but through either Toad or SQL Plus. I've gotten these same errors in both.
    Though MS Access runs slow as snails, I can manage to run the update statement successfully with it, a thousand records or so at a time. Problem is, I've got about 300K records needing updating.
    I've looked around for similar problems but haven't found one where someone wasn't either using a reserved word for a column, which I'm not, I don't believe, or a problem that really dealt with this error in the context of an update statement.
    But I'd welcome any enlightenment on this.

    rp0428 wrote:
    UPDATE TBL_ARCHIVE a
    SET a.ZIP = TBL_UAT.ZIP
    WHERE TBL_UAT.ID = a.ID;That isn't a valid query and neither is the other one.
    Please post the actual query you are using and the actual complete error message you are getting (everything about the error that is displayed).^^
    That is NOT a valid query?
    How else would you have an UPDATE statement created to set the value of a column in table A to the value of a (in this case, same named) column in table B?
    And keep them in order to update the records appropriately?
    I'll append the create statements momentarily.
    Thanks!
    CREATE TABLE TBL_UAT
    ( ID NUMBER(6),
    ZIP VARCHAR2(10 BYTE) ) and
    CREATE TABLE TBL_ARCHIVE
    ( ID NUMBER(6) NOT NULL, NAME VARCHAR2(50 BYTE),
    EMAIL VARCHAR2(50 BYTE),
    LOCATION VARCHAR2(50 BYTE),
    DEPARTMENT VARCHAR2(50 BYTE),
    PRIORITY VARCHAR2(50 BYTE),
    APPROVING_MGR_NAME VARCHAR2(50 BYTE),
    TYPE1 VARCHAR2(50 BYTE),
    TYPE2 VARCHAR2(50 BYTE),
    CONTACT_NAME VARCHAR2(50 BYTE),
    CONTACT_PHN_NO VARCHAR2(50 BYTE),
    LOAN_NUM VARCHAR2(50 BYTE),
    REF_ID VARCHAR2(50 BYTE),
    BORROWER_NAME VARCHAR2(50 BYTE),
    ADDRESS VARCHAR2(50 BYTE),
    CITY VARCHAR2(50 BYTE),
    ST VARCHAR2(50 BYTE),
    ZIP VARCHAR2(10 BYTE),
    SALE_DATE DATE,
    COMMENTS VARCHAR2(800 BYTE),
    TIME_REQ DATE,
    ACCTLOC VARCHAR2(50 BYTE),
    OTHER_ACCTLOC VARCHAR2(50 BYTE)) Hope this can be of assistance.
    Thanks, folks!
    Edited by: user515689 on Feb 7, 2012 11:59 AM

  • Use of ROWID in SQL Update Statement

    Hi All,
    I have an update statement which uses the rowid column to perform the selection on the target table. Given that a rowid represents the physical location of a row on disk we know that this reference can change when various activities are performed on the database/table/row etc...
    Here is an example of the statement I am issuing:
    UPDATE tabA outertab SET col1 = 'Value'
    WHERE EXISTS (SELECT 1 FROM tabA innertab WHERE outertab.ROWID = outertab.ROWID AND ...)
    Obviously the inner query is more complicated and uses other tables etc... but for the purposes of the example we dont need to include the detail.
    My question is: When using rowid in a single SQL statement as a reference from a subquery to the outer statement is there a risk that external activities can change the rowid and those changes be reflected within the database session that my query is executing thus causing an inconsistency between the inner and outer SQL clause?
    In response to the question which will follow this post: "Why don't you just use a PK", We would like to avoid maintaining a PK on the table as we are talking about very large volumes of data and we dont want to have to issue a call to a sequence if we can avoid it when we are inserting the data. If however there is a risk that this Update statement could fail or update the wrong rows then we may have to use a PK.
    I know there is a lot of threads about this but I havnt been able to find one that someone has answered with any kind of confidence or clarity, any help would be much appreciated.
    Thanks
    Keith
    Edited by: The Turtle on Mar 5, 2009 5:24 AM

    When using rowid in a single SQL statement as a reference from a subquery to the outer statement is there a risk that external activities can change the rowid and those changes be reflected within the database session that my query is executing thus causing an inconsistency between the inner and outer SQL clause?No, it's safe to use rowid in this type of query. Docs
    A row's assigned rowid remains unchanged unless the row is exported and imported using the Import and Export utilities. When you delete a row from a table and then commit the encompassing transaction, the deleted row's associated rowid can be assigned to a row inserted in a subsequent transaction.

  • UPDATING the query in materialized view

    Hi,
    i have a little doubt in Materialized view. i created a materialized view and log with the following query,
    create table test_mv (a number ,b number )
    alter table test_mv add constraint t_pk primary key ( a );
    insert into test_mv values (1,2);
    insert into test_mv values(2,2);
    insert into test_mv values(3,2);
    insert into test_mv values(4,2);
    insert into test_mv values(5,2);
    commit;
    CREATE MATERIALIZED VIEW LOG ON test_mv
    WITH SEQUENCE, ROWID
    *(a,b)*
    INCLUDING NEW VALUES;
    CREATE MATERIALIZED VIEW product_sales_mv
    ENABLE QUERY REWRITE
    AS SELECT  b  from test_mv;
    Now i want to update the query in the MV as 'Select a from test_mv' . for that i tried with
    *'ALTER MATERIALIZED VIEW product_sales_mv AS SELECT a from test_mv;'*
    But it throwing error,
    Error starting at line 5 in command:
    alter  MATERIALIZED VIEW product_sales_mv   AS SELECT  b  from test_mv
    Error report:
    SQL Error: ORA-00933: SQL command not properly ended
    +00933. 00000 - "SQL command not properly ended"+
    *Cause:+   
    *Action:+
    i guess i am doing wrong. kindly help me here. i want to update it without drop and recreate.
    thanks,
    Jeevanand.Ke

    Hi Jeeva,
    No. you cannot add or drop columns to the materialized view using the ALTER Statement.
    To Change the Structure of the view , drop and re-create the materialized view.
    To Alter a materialized view log, You can use the ALTER MATERIALIZED VIEW LOG. By this,
    You can add new columns to a materialized view log.
    ALTER MATERIALIZED VIEW LOG ON sggi_mrps.emp ADD(deptno);Thanks,
    Shankar
    Edited by: Shankar Viji on Aug 24, 2012 2:11 AM

  • Error in update statement

    Hai All
    update dail set timeout=out_time where attend_date=r1.bardate and
    (select bar_code from empl_barcode where empl_barcode.barcode=r1.barcode);
    I got an error in my update statement. How can i write update statement with this or where i change..
    Regards
    Srikkanth.M

    Hi,
    review the syntax for the UNDATE statement. The following is okay:
    UPDATE     dail
    SET     timeout          = out_time
    WHERE     attend_date     = x
    AND     y          > z
    ;if all the columns (including x, y and z) are in dail.
    If you need to get some of those values from another table, then you can do a scalar sub-query , that is, a query that returns 9at most) one row, enclosed in parentheses.
    For example, if x is in another table (named r1), you might say:
    UPDATE     dail     m
    SET     timeout          = out_time
    WHERE     attend_date     = (     -- Begin scalar sub-query
                        SELECT     MAX (bardate)
                        FROM     r1
                        WHERE     dail_id     = m.id
                     )     -- End scalar sub-query
    AND     y          > z
    ;It looks like you're trying to do something similar.
    I'm not sure exactly what x is supposed to be, and you're missing y (or z) as well as the operator between them.
    MERGE is often easier to use than UPDATE, when you need to reference other tables.
    If you'd like help, post a little sample data (CREATE TABLE and INSERT statements for all tables as they exist before the UPDATE) and the results you want from taht data (the contents of dail after the UPDATE).

  • Problem in Update statement using Execute Immediate

    Hi All,
    I am facing problem in update statement.
    I am creating dynamic sql and use "execute immediate" statement to execute a update statement.
    But it is not updating any thing there in the table.
    I have created a query like :
    update_query='Update '|| Table_Name ||' t set t.process_status =''Y'' where t.tid=:A';
    Execute immediate update_query using V_Id;
    commit;
    But it is not updating the table.
    I have a question , is execute immediate only does insert and delete?
    Thanks
    Ashok

    SQL> select * from t;
                     TID P
                     101 N
    SQL> declare
      2     V_Id          number := 101;
      3     Table_Name    varchar2(30) := 'T';
      4     update_query  varchar2(1000);
      5  begin
      6     update_query := 'Update '|| Table_Name ||' t set t.process_status =''Y'' where t.tid=:A';
      7     Execute immediate update_query using V_Id;
      8     commit;
      9  end;
    10  /
    PL/SQL procedure successfully completed.
    SQL> select * from t;
                     TID P
                     101 Y                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Join in update statement

    can we use join in update statement?
    here is the query which is giving me error
    UPDATE      pol_int_name_multiple_v
    SET      PMV.client_seq_nbr_i = 1
    FROM     pol_int_name_multiple_v PMV
    JOIN      pol_int_name PIV
    ON      piv.int_name_id = pmv.int_name_id
    WHERE      piv.client_id = 5
    SQL> /
    FROM pol_int_name_multiple_v PMV
    ERROR at line 3:
    ORA-00933: SQL command not properly ended
    Message was edited by:
    aadi

    Yes, you can. The table with updateble columns must be a key preserved table. See http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96590/adg03sch.htm#1044
    Example:
    SQL> CREATE TABLE A(A INTEGER PRIMARY KEY);
    Table created.
    SQL> INSERT INTO A VALUES(1);
    1 row created.
    SQL> INSERT INTO A VALUES(2);
    1 row created.
    SQL> COMMIT;
    Commit complete.
    SQL> CREATE TABLE B(
      2    A INTEGER,
      3    B INTEGER,
      4    FOREIGN KEY(A) REFERENCES A);
    Table created.
    SQL> INSERT INTO B(A, B) VALUES(1, 5);
    1 row created.
    SQL> INSERT INTO B(A, B) VALUES(2, 5);
    1 row created.
    SQL> INSERT INTO B(A, B) VALUES(2, 10);
    1 row created.
    SQL> COMMIT;
    Commit complete.
    SQL> SELECT * FROM B;
             A          B
             1          5
             2          5
             2         10
    SQL> UPDATE
      2    (
      3      SELECT B.*
      4      FROM A JOIN B ON A.A = B.A
      5      WHERE B.A = 2
      6    )
      7    SET B = 333;
    2 rows updated.
    SQL> COMMIT;
    Commit complete.
    SQL> SELECT * FROM B;
             A          B
             1          5
             2        333
             2        333Regards,
    Dima

  • Sudden increase in buffer gets per executions in update statement

    Hi,
    Recently we have encountered one performance issue, which is most likely caused by a sudden increase in the buffer gets per execution.
    The SQL is an update statement, updating a table using a primary key (we have checked to confirm the running execution plan is using the primary key), and one field being updated is a BLOB column.
    As shown in the below statistics, there is no major change in the number of executions during the every 20 minutes monitoring interval. However, the buffer gets per executions has been more than double, and the CPU time is almost doubled, hence the exec_time (elapsed time) has been doubled.
    The same SQL has been running for the past four years in multiple similar databases. The database is Oracle 9.2.0.4 running on Solaris 9. For the past 300 days, the average elapsed time per execution is about 0.0093s, while the average buffer gets per execution is about 670. The update statement has been executed about 9 times per second.
    The question is why there is a sudden increase in the buffer gets? The sudden increase happened twice for the past two days.
    <pre>
    B_TIME E_TIME EXECUTIONS_DIFF EXEC_TIME CPU_TIME BUFFER_GETS EXEC_PER_DAY
    2009-11-25-14:04 2009-11-25-14:23 8513 .0069 .0068 315.56 646329
    2009-11-25-14:23 2009-11-25-14:43 10170 .007 .0068 312.28 726188
    2009-11-25-14:43 2009-11-25-15:05 11873 .0072 .0069 320.17 787885
    2009-11-25-15:05 2009-11-25-15:23 8633 .011 .0101 844.83 675014
    2009-11-25-15:23 2009-11-25-15:44 9668 .0144 .0137 1448.51 680778
    2009-11-25-15:44 2009-11-25-16:04 9671 .0163 .0156 1809.04 702163
    2009-11-25-16:04 2009-11-25-16:25 10260 .0188 .0177 2107.67 711447
    2009-11-25-16:25 2009-11-25-16:44 9827 .0157 .0151 1834.3 739593
    2009-11-25-16:44 2009-11-25-17:05 10586 .0171 .0164 2008.25 714555
    2009-11-26-08:04 2009-11-26-08:24 11028 .0182 .0172 1979.61 800688
    2009-11-26-08:24 2009-11-26-08:44 10533 .0154 .0149 1734.62 750248
    2009-11-26-08:44 2009-11-26-09:04 9367 .018 .0168 2043.95 685274
    2009-11-26-09:04 2009-11-26-09:24 10307 .0214 .0201 2552.43 729938
    2009-11-26-09:24 2009-11-26-09:45 10932 .0251 .0234 3111.48 762328
    2009-11-26-09:45 2009-11-26-10:05 10992 .0278 .0254 3386.41 797404
    2009-11-26-15:03 2009-11-26-15:16 7183 .0425 .0348 4615.42 746824
    2009-11-26-15:16 2009-11-26-15:23 2921 .0417 .0373 4887.75 682092
    2009-11-26-15:23 2009-11-26-15:43 9597 .0393 .0352 4603.62 679656
    2009-11-26-15:43 2009-11-26-16:03 8797 .0411 .0362 4783.66 630755
    2009-11-26-16:03 2009-11-26-16:23 9957 .0453 .0391 5168.28 718100
    2009-11-26-16:23 2009-11-26-16:43 11209 .0436 .0369 4870.77 808395
    2009-11-26-16:43 2009-11-26-17:03 10729 .0428 .0375 5119.56 766103
    2009-11-26-17:03 2009-11-26-17:23 9116 .0409 .0363 4912.58 659098
    </pre>
    Yesterday I did a trace on one of the sessions running the update statement, and below is the tkprof output:
    <pre>
    call count cpu elapsed disk query current rows
    Parse 76 0.03 0.00 0 0 0 0
    Execute 76 4.58 5.14 0 567843 19034 76
    Fetch 0 0.00 0.00 0 0 0 0
    total 152 4.61 5.14 0 567843 19034 76
    Misses in library cache during parse: 1
    Optimizer goal: CHOOSE
    Parsing user id: 88
    Rows Row Source Operation
    1 UPDATE (cr=30 r=0 w=0 time=6232 us)
    1 INDEX UNIQUE SCAN <PK Index Name> (cr=3 r=0 w=0 time=58 us)(object id 81122)
    Elapsed times include waiting on following events:
    Event waited on Times Max. Wait Total Waited
    Waited--------------------------------------------------------------------------------
    SQL*Net message to client 152 0.00 0.00
    SQL*Net message from client 152 0.00 0.22
    SQL*Net more data from client 1894 0.00 0.03
    SQL*Net break/reset to client 152 0.00 0.00
    buffer busy waits 14 0.00 0.00
    enqueue 1 0.61 0.61
    </pre>
    GaoYuan

    Hi,
    I've reformatted your output for better understanding (with {noformat}...{noformat}):
    B_TIME           E_TIME           EXECUTIONS_DIFF  EXEC_TIME   CPU_TIME BUFFER_GETS EXEC_PER_DAY
    2009-11-25-14:04 2009-11-25-14:23            8513      .0069      .0068      315.56       646329
    2009-11-25-14:23 2009-11-25-14:43           10170       .007      .0068      312.28       726188
    2009-11-25-14:43 2009-11-25-15:05           11873      .0072      .0069      320.17       787885
    2009-11-25-15:05 2009-11-25-15:23            8633       .011      .0101      844.83       675014
    2009-11-25-15:23 2009-11-25-15:44            9668      .0144      .0137     1448.51       680778
    2009-11-25-15:44 2009-11-25-16:04            9671      .0163      .0156     1809.04       702163
    2009-11-25-16:04 2009-11-25-16:25           10260      .0188      .0177     2107.67       711447
    2009-11-25-16:25 2009-11-25-16:44            9827      .0157      .0151      1834.3       739593
    2009-11-25-16:44 2009-11-25-17:05           10586      .0171      .0164     2008.25       714555
    2009-11-26-08:04 2009-11-26-08:24           11028      .0182      .0172     1979.61       800688
    2009-11-26-08:24 2009-11-26-08:44           10533      .0154      .0149     1734.62       750248
    2009-11-26-08:44 2009-11-26-09:04            9367       .018      .0168     2043.95       685274
    2009-11-26-09:04 2009-11-26-09:24           10307      .0214      .0201     2552.43       729938
    2009-11-26-09:24 2009-11-26-09:45           10932      .0251      .0234     3111.48       762328
    2009-11-26-09:45 2009-11-26-10:05           10992      .0278      .0254     3386.41       797404
    2009-11-26-15:03 2009-11-26-15:16            7183      .0425      .0348     4615.42       746824
    2009-11-26-15:16 2009-11-26-15:23            2921      .0417      .0373     4887.75       682092
    2009-11-26-15:23 2009-11-26-15:43            9597      .0393      .0352     4603.62       679656
    2009-11-26-15:43 2009-11-26-16:03            8797      .0411      .0362     4783.66       630755
    2009-11-26-16:03 2009-11-26-16:23            9957      .0453      .0391     5168.28       718100
    2009-11-26-16:23 2009-11-26-16:43           11209      .0436      .0369     4870.77       808395
    2009-11-26-16:43 2009-11-26-17:03           10729      .0428      .0375     5119.56       766103
    2009-11-26-17:03 2009-11-26-17:23            9116      .0409      .0363     4912.58       659098
    call     count       cpu    elapsed       disk      query    current        rows
    Parse       76      0.03       0.00          0          0          0           0
    Execute     76      4.58       5.14          0     567843      19034          76
    Fetch        0      0.00       0.00          0          0          0           0
    total      152      4.61       5.14          0     567843      19034          76
    Misses in library cache during parse: 1
    Optimizer goal: CHOOSE
    Parsing user id: 88
    Rows     Row Source Operation
          1  UPDATE  (cr=30 r=0 w=0 time=6232 us)
          1   INDEX UNIQUE SCAN <PK Index Name(cr=3 r=0 w=0 time=58 us)(object id 81122)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      SQL*Net message to client                     152        0.00          0.00
      SQL*Net message from client                   152        0.00          0.22
      SQL*Net more data from client                1894        0.00          0.03
      SQL*Net break/reset to client                 152        0.00          0.00
      buffer busy waits                              14        0.00          0.00
      enqueue                                         1        0.61          0.61
    ********************************************************************************Can you please provide a DDL for the table, indexes, type of the tablespace(s) they reside in (ASSM/MSSM, extents sizes), the UPDATE statement, how many sessions on average/peaks are doing the same thing concurrently, how many sessions are working this table concurrently and how do they use it?

  • Update- statement in JDBC sender Adapter

    Hi ,
    I have a requirement where I am trying to fetch data from ODS based on some flag and immediately I want to update the flag status . So I used selected and update in JDBC sender adapter .
    But I have one question , in the small timeframe where  XI has done a select and just before  XI could  issue the update statement  if a new record is added to ODS . Then  that new record will also get updated though it wasnot selected in select statement .
    Can someone let me know how to overcome this problem ; as I want to make sure I update only those recrods which are selected in select statement ??
    Thanks & Regards,
    Suvarna

    Hi,
    Check out the following thread. It gives the exact answer to this question.
    JDBC Sender Update Query
    One of the replies in the above thread:
    I put in an OSS note asking this exact question with your specific example, and got a reply. I was referred to OSS note 0000831162, where it is explained very unambiguously that the SELECT and UPDATE queries are run in the same transaction.
    Regards,
    P.Venkat
    Message was edited by:
            Venkataramanan

Maybe you are looking for

  • Populating the request attributes in Application Instance forms of OIM11gR2

    Hi, We have configured request based provisioning for the 3 target applications. As a process 1) Manager is log in to OIM Identity console and selects the one user and provision the application Instance after selecting the required roles in the Appli

  • Is my CPU really overloaded....why all the crashes?

    I'm on a quad core G5 with oodles of RAM running 10 or so tracks of pretty big multilayered Audio Instruments. My monitors say I've plenty of RAM left and plenty of CPU power to spare. In fact only 3 of the 4 processors seem to be being used. But I k

  • Can't open Numbers because Update

    I need to show my business plan for my customers. But my numbers can't open because update. Wait...wait and update....update .....make me crazy!

  • Message type E and inactive fields

    Hi, After: MESSAGE e001(00) WITH text-t001 all fields on screen becomes inactive even when I press enter. What is a correct flow logic for a screen to make screen field visible after enter key press immediatelly after error message occurs ?  thx a lo

  • Deleting Master Data via Process Chain

    I am in the midst of creating a process chain and am able to create process for deleting ODS Contents, but am not able to do the same for Master Data. Is this possible?