Multiple updates to same row

Hi experts,
I still cant figure out how oracle handles multiple updates to the same row. For instance I have 3 update statements:
update supplier set supp_type = 'k' where supp_code = '1';
update supplier set supp_type = 'j' where supp_code = '1';
update supplier set supp_type = 'm' where supp_code = '1';
I keep getting the final result to be supp_type = 'k' where it should actually be 'm', but when i execute the mapping it shows 3 update operations, which baffled me as to how oracle handles simultaneous updates to same row. I even tried disabling parallel dml on the table object, but am unsure whether this actually helps. I try putting a sorter operator and then a key lookup operator after the sorter operator in my mapping to compare the supp_code field in the sorter with the target table's supp_code field to retrieve the relevant row to update, but instead of 3 update operations, it now updates all supp_type in all my records to NULL. Can anyone explain to me how i should go about dealing with this?

Hi experts,
I just took a look at the code section generated for the key lookup operator named SUPPLIER_WH_SURRKEY01 and I feel something is wrong with the generated code. I have pasted the code section on the key lookup operator below.
ORDER BY
"SUPPLIER_CV"."RSID$" ASC ) *"SORTER" ON ( ( ( "SUPPLIER_WH_SURRKEY01"."EXPIRATION_DATE" = "SPIDERWEB2"."GET_EXPIRATI_0_EXPIRATI" ) ) AND ( ( "SUPPLIER_WH_SURRKEY01"."SUPPCODE" = "SORTER"."SUPP_CODE$1" ) ) )*
WHERE
( ( "SUPPLIER_WH_SURRKEY01"."SUPPKEY" IS NULL ) OR ( "SUPPLIER_WH_SURRKEY01"."SUPPKEY" = "SUPPLIER_WH_SURRKEY01"."SUPPKEY" ) );
Can anyone explain to me the codes in bold? I have no clue as to what it means? Furthermore, those bold-ed codes look similar to what I have expected to find in the where clause, except that instead of SUPPLIER_WH_SURRKEY01"."EXPIRATION_DATE" = "SPIDERWEB2"."GET_EXPIRATI_0_EXPIRATI", I expected to find
SUPPLIER_WH_SURRKEY01"."EXPIRATION_DATE" = '31-dec-4000', because my key lookup operator checks upon a constant with the value '31-dec-4000'. And the constant name is CONSTANT itself, while my mapping's name is SPIDERWEB2(not too sure why the generated code refers to my mapping name instead of my constant)
Edited by: user8915380 on 17-Mar-2010 00:52

Similar Messages

  • Insert a field and update the same row.

    Hi,
    I am inserting a value in a row.
    And later within a cursor loop I am trying to update the same row. But it is not working....
    CREATE OR REPLACE procedure Del_Note_stage
    Is
    v_delNote Delivery_Note.Delivery_Note_id%type;
    Cursor C1 is Select Heading_Name,File_Data from Sqlload_Stage;
    Begin
    dbms_output.put_line('i am here a ');
    Select Delivery_Note_Id_Seq.nextval into v_delNote from dual;
    Insert into DELIVERY_NOTE_STAGING(Delivery_Note_ID,LUT,LUB,PROCESSED) Values(v_delNote,sysdate,'Config','N');
    commit;
    dbms_output.put_line('i am here b'||v_delNote);
    For sqlload_rec in C1
       Loop
        dbms_output.put_line(sqlload_rec.Heading_Name);
        dbms_output.put_line('Del Note Id is :'||v_delNote);
        update DELIVERY_NOTE_STAGING  set deployed_by='TOM' where delivery_note_id=v_delNote;
    End loop;
    End;

    But it is not working....Why not?
    Please read: http://tkyte.blogspot.com/2005/06/how-to-ask-questions.html
    Why are you updating after inserting?
    Just add deployed_by to the insert statement, or use a default value for that column.
    Also you don't need to select your Delivery_Note_Id_Seq.nextval from dual, just use it in your insert statement.
    Something like:
    Insert into DELIVERY_NOTE_STAGING(Delivery_Note_ID,LUT,LUB,PROCESSED,deployed_by )
    Values( Delivery_Note_Id_Seq.nextval,sysdate,'Config','N', 'TOM' /*or USER*/);

  • Updating the same row in different sessions

    Hi,
    I've one table application(appl_no varchar2(10), locked_user varchar2(8)) which is used to track which user is logged in at present.
    As soon as any user is logged in to the system via front end, the user ID is populated to locked_user column so that no other user cannot access the same appl_no. As soon as the user exits from the front end, the locked_user is updated to null.
    We've experiencing a strange behaviour in our system where one user exits from front end and at the same time(previous transaction is not committed) the same user ID opens the same application in another session, but the session session doesn't gets hanged(waiting for the lock to be released) and tries to update the same row which was locked by first user's session. We come to know this thing when the trigger on the table gets fired in both sessoins.
    Now I want to know if there is any locking machanism in Oracle where the same row can be updated in 2 different sessons one after another when the first session has not committed its changes?
    Thanks
    Deepak

    And obviously no two sessions can update the same record at the same time
    Yes I know that and I tried the same thing by myself on 2 different sql sessions which is not happening, but this is happening when the same is being done from front end(Power Builder based application).
    Just wanted to check is there any possibility where this can be possible?
    Thanks
    Deepak

  • Insert then update on same row in bean Transaction leads to deadlock

    <b>Setup Details</b>
    Hibernate version: 3.1.2
    EJB version: 2.0
    Name and version of the database : MS SQL Server 2000
    Datasource implmentation class being used : com.sap.nwmss.jdbcx.sqlserver.SQLServerDataSource
    We are using SAP NetWeaver Application Server 6.0 and Hibernate 3.1.2 in our application. We have StalessSessionBeans which use Hibernate to interact with the database. We are running into a situation where the application goes into a hang state when the following flow is bein executed:
    //transaction attribute = "Required"
    beanMethod() {
    myObj = new MyObj();
    myObj.setSomeValue();
    session = SessionFactory.openSession();
    //id is auto generated by database
    id = session.insert(myObj);
    //retrieve the recently inserted obj
    myUpdatedObj = session.load(id);
    //modify the myUpdatedObj
    myUpdatedObj.modifySomeValue();
    //update using hibernate session
    session.update(myUpdatedObj);
    //return from method 
    Here's the flow:
    1) In a CMT stateless session bean, there's a method which has transaction atrribute as "Required"
    2) This method creates a new object and inserts it
    3) Then loads this saved object and modifies some values in it
    4) Then invokes the update method on the session to update this modified object in the database.
    Note: We have enabled auto flush on transaction in the hibernate configuration file.
    And here's what we are observing:
    - The insert obtains a lock on the row as part of the transaction
    - When the update is called on the same row as part of the auto flush, the update never completes. The update statement is unable to obtain a lock on the same row.
    Here is some additional info:
    - We have set :
    session.connection().setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
    hibernate.cfg.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-configuration PUBLIC
                "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
                "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
    <hibernate-configuration>
       <session-factory>
          <property name="hibernate.jndi.class">
             com.sap.engine.services.jndi.InitialContextFactoryImpl
          </property>
          <property name="hibernate.session_factory_name">
             HibernateSessionFactory
          </property>
          <property name="hibernate.transaction.factory_class">
             org.hibernate.transaction.JTATransactionFactory
          </property>
          <property name="hibernate.connection.datasource">jdbc/SQLPool1</property>
          <property name="hibernate.connection.pool_size">25</property>
          <property name="show_sql">true</property>
          <property name="hibernate.connection.isolation">1</property>
          <property name="hibernate.prepare_sql">true</property>
          <property name="hibernate.statement_cache.size">10000</property>
          <!--property name="hibernate.jdbc.use_scrollable_resultset">true</property-->
          <property name="transaction.manager_lookup_class">
             com.tdemand.server.util.hibernate.SAPWebASTransactionManagerLookup
          </property>
          <property name="hibernate.jdbc.use_get_generated_keys">
                   false
          </property>
          <property name="hibernate.transaction.flush_before_completion">true</property>
          <property name="hibernate.jdbc.batch_size">1000</property>
          <property name="hibernate.cache.use_second_level_cache">false</property>
       </session-factory>
    </hibernate-configuration>
    Any clue why the update query is having problem in completing, even though update and insert are being called from the same bean method as part of a transaction?
    Here's the log:
    2006-11-01 22:10:00,310 INFO [com.tdemand.server.planning.ejbs.ForecastPlanningSessionBean] - Starting save
    2006-11-01 22:10:00,310 DEBUG [org.hibernate.event.def.DefaultSaveOrUpdateEventListener] - saving transient instance
    2006-11-01 22:10:00,310 DEBUG [org.hibernate.event.def.DefaultSaveOrUpdateEventListener] - saving transient instance
    2006-11-01 22:10:00,310 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] - saving [com.tdemand.generated.pojo.TdForecastPlan#<null>]
    2006-11-01 22:10:00,310 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] - saving [com.tdemand.generated.pojo.TdForecastPlan#<null>]
    2006-11-01 22:10:00,310 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] - executing insertions
    2006-11-01 22:10:00,310 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] - executing insertions
    2006-11-01 22:10:00,310 DEBUG [org.hibernate.persister.entity.BasicEntityPersister] - Inserting entity: com.tdemand.generated.pojo.TdForecastPlan (native id)
    2006-11-01 22:10:00,310 DEBUG [org.hibernate.persister.entity.BasicEntityPersister] - Inserting entity: com.tdemand.generated.pojo.TdForecastPlan (native id)
    2006-11-01 22:10:00,310 DEBUG [org.hibernate.jdbc.AbstractBatcher] - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
    2006-11-01 22:10:00,310 DEBUG [org.hibernate.jdbc.AbstractBatcher] - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
    2006-11-01 22:10:00,325 DEBUG [org.hibernate.SQL] - insert into trd0nedbo.TD_FORECAST_PLAN (ORGANIZATION_TBL_ID, USER_TBL_ID, PLAN_NAME, IS_ACTIVE, PLAN_TYPE, TIMECREATED, TIMEUPDATED, START_TIME, END_TIME, HORIZON, HORIZON_UOM, REVIEW_FREQ, ACCU_THRESHOLD, REVIEW_FREQ_UOM, FORECAST_METRIC, BASE_FORECAST, PRECISION_FORECAST, ADJUSTED_FORECAST, ORG_ID, CRON_TRIG_NAME) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) select scope_identity()
    2006-11-01 22:10:00,325 DEBUG [org.hibernate.SQL] - insert into trd0nedbo.TD_FORECAST_PLAN (ORGANIZATION_TBL_ID, USER_TBL_ID, PLAN_NAME, IS_ACTIVE, PLAN_TYPE, TIMECREATED, TIMEUPDATED, START_TIME, END_TIME, HORIZON, HORIZON_UOM, REVIEW_FREQ, ACCU_THRESHOLD, REVIEW_FREQ_UOM, FORECAST_METRIC, BASE_FORECAST, PRECISION_FORECAST, ADJUSTED_FORECAST, ORG_ID, CRON_TRIG_NAME) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) select scope_identity()
    2006-11-01 22:10:00,325 DEBUG [org.hibernate.jdbc.AbstractBatcher] - preparing statement
    2006-11-01 22:10:00,325 DEBUG [org.hibernate.jdbc.AbstractBatcher] - preparing statement
    2006-11-01 22:10:00,325 DEBUG [org.hibernate.persister.entity.BasicEntityPersister] - Dehydrating entity: [com.tdemand.generated.pojo.TdForecastPlan#<null>]
    2006-11-01 22:10:00,325 DEBUG [org.hibernate.persister.entity.BasicEntityPersister] - Dehydrating entity: [com.tdemand.generated.pojo.TdForecastPlan#<null>]
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.LongType] - binding '6' to parameter: 1
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.LongType] - binding '6' to parameter: 1
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.LongType] - binding '1' to parameter: 2
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.LongType] - binding '1' to parameter: 2
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'jaikiranpai' to parameter: 3
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'jaikiranpai' to parameter: 3
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'Y' to parameter: 4
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'Y' to parameter: 4
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'RetailDCOrderForecast' to parameter: 5
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'RetailDCOrderForecast' to parameter: 5
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.TimestampType] - binding '2006-11-01 22:10:00' to parameter: 6
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.TimestampType] - binding '2006-11-01 22:10:00' to parameter: 6
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.TimestampType] - binding null to parameter: 7
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.TimestampType] - binding null to parameter: 7
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.TimestampType] - binding '2006-11-01 22:10:00' to parameter: 8
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.TimestampType] - binding '2006-11-01 22:10:00' to parameter: 8
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.TimestampType] - binding null to parameter: 9
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.TimestampType] - binding null to parameter: 9
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.BigDecimalType] - binding '14' to parameter: 10
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.BigDecimalType] - binding '14' to parameter: 10
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'DAY' to parameter: 11
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'DAY' to parameter: 11
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.BigDecimalType] - binding '7' to parameter: 12
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.BigDecimalType] - binding '7' to parameter: 12
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.BigDecimalType] - binding '0' to parameter: 13
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.BigDecimalType] - binding '0' to parameter: 13
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'DAY' to parameter: 14
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'DAY' to parameter: 14
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'MAPE' to parameter: 15
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'MAPE' to parameter: 15
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding null to parameter: 16
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding null to parameter: 16
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding null to parameter: 17
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding null to parameter: 17
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding null to parameter: 18
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding null to parameter: 18
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.BigDecimalType] - binding null to parameter: 19
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.BigDecimalType] - binding null to parameter: 19
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding null to parameter: 20
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding null to parameter: 20
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.id.IdentifierGeneratorFactory] - Natively generated identity: 103
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.id.IdentifierGeneratorFactory] - Natively generated identity: 103
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.jdbc.AbstractBatcher] - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.jdbc.AbstractBatcher] - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.jdbc.AbstractBatcher] - closing statement
    2006-11-01 22:10:00,341 DEBUG [org.hibernate.jdbc.AbstractBatcher] - closing statement

    "insert into aa values ('1', '2', '3','4','5',6,7);
    if sql%rowcount <> 1 then
    RAISE_APPLICATION_ERROR(-20999, 'insert aa err');
    END IF;
    /* skip some code
    update aa set dept_code = '3' where fee_month = '1';
    if sql%rowcount <> 1 then"
    Is Dept_Code the 2nd Column in the table aa. If so then
    why update the table ?
    Why not Insert Into aa Values ('1', '3', '3' ......);
    Have a look at the sample script which is doing Insert followed by updating the same table using the ROWID.
    Test Db>desc temp;
    Name Null? Type
    COL1 VARCHAR2(10)
    COL2 VARCHAR2(10)
    COL3 VARCHAR2(10)
    COL4 VARCHAR2(10)
    ID NUMBER
    Test Db>select * from temp;
    no rows selected
    Test Db>get t1
    1 Set ServerOutput On Size 999999;
    2 Declare
    3 lRow Varchar2(50);
    4 Begin
    5 Insert Into Temp (Col1, Col2, Col3, Col4, Id)
    6 Values ('A', 'B', 'C', 'D', 100)
    7 RETURNING RowId Into lRow;
    8 Dbms_Output.Put_Line ('RowId = ' || lRow);
    9 Update Temp Set col2 = 'B1'
    10 Where RowId = lRow;
    11 Dbms_Output.Put_Line ('Row Updated');
    12* End;
    13 /
    Test Db>@t1
    RowId = AAAKsqAAJAAAEbsAAG
    Row Updated
    PL/SQL procedure successfully completed.
    Test Db>select * from temp;
    COL1 COL2 COL3 COL4 ID
    A B1 C D 100
    -- Shailender Mehta --

  • Insert a field twice (that has multiple values) onto same row in report

    I am new to design so hopefully this is an easy question...
    I have three tables in my report that are linked.
    Table 1  "TMDE"
    Mfg
    Model
    Type_Id  (Linked to "FEE(PRICE)"
    Table 2 "FEE"
    Price
    Service_ID (Linked to "SERVICE(ID)"
    Table 3  "SERVICE"
    ID
    Service_Type
    What I am trying to do is create a report that displays two different prices based on two diffent Service "ID"'s on the same row.
    My report keeps creating a second row for the second Service "ID"
    Example:
    MFG      MODEL    TYPE                         PRICE
    Fluke      87         Calibration                  $40.00
    Fluke      87         Calibration w/data     $60.00
    What I woiuld like to see is:
    MFG     MODEL                Calibration $        Calibration w/data $
    Fluke     87                           40.00                     60.00
    Can you help?

    Thanks Noel but I don't think that is the answer.
    Let me try to explain a little further...
    My TMDE table has a field called "Type_ID".  Let's say that record 1 has a "Type_ID" field value of 27.  The "Typer_ID" field is linked to the PRICE table. The linked field in the PRICE table is called "ID" "ID" may have several 27 valuies for the different prices. These prices are based on the PRICE"Service_ID" field.
    Hopefully, this will explain it better...
    TABLE:TMDE 
    MFG:Fluke;   MOIDEL:87;   TYPE_ID:27 (linked to PRICE:ID)
    TABLE:PRICE
    ID:27;        FEE:40;    SERVICE_ID:1 (linked to SERVICE:ID
    ID:27;        FEE:50;    SERVICE_ID:2 (linked to SERVICE:ID
    ID:27;        FEE:60;    SERVICE_ID:3 (linked to SERVICE:ID
    TABLE:SERVICE
    ID:1;  TYPE:Calibration
    ID:2;  TYPE:Calibration w/data
    ID:3;  TYPE:Calibration-Accredtied
    What I would like to see is:
    MFG       MODEL       Calbration price          Calibration w/Data Price
    Fluke      87                       40                                     50
    Thanks

  • Update on same row

    Can someone help me to solve update on table
    SQL> select * from emp_addr;
    EMP_NAME        EMP_ADD
    SAM             15, Telok Kurau Rd
    SAM             205,Alexandra Rd
    JON             78, Sin Ming Dr
    ADAM            803, Coton Gren rd
    ADAM            Ubi Rd 4
    ADAM            Defu Lane 10
    6 rows selectedThe output should be like
    SQL> select * from emp_addr;
    EMP_NAME        EMP_ADD
    SAM_1             15, Telok Kurau Rd
    SAM_2             205,Alexandra Rd
    JON_1             78, Sin Ming Dr
    ADAM_1            803, Coton Gren rd
    ADAM_2            Ubi Rd 4
    ADAM_3            Defu Lane 10
    6 rows selectedrgds
    saaz

    merge into t
    using (select rowid
                , emp||'_'||row_number() over (partition by emp
                                                   order by emp_add
                                              ) new_emp
            from t
          ) x
      on (t.rowid = x.rowid)
    when matched then update set emp = new_emp
    ;

  • Multiple Views of Same Rows from a Tabbed Pane

    I have a Tabbed Pane with several Tabs that access Different Tables. One Table is the child of two different Tables, ie one foreign key on the child that that points to Table A and a second foreign key on the child that points to Table B. I am trying to have a tabbed pane that will show the childs rows one based on the Table A Foreign Key and the second based on the Table B Foreign Key.
    No matter what I have tried, I get only one view from both Tabs. (NOTE: Both of the Tabbed pane that I instantiate from look completly different, ie a different sequence of fields.)
    I have two distinct rowsetinfo's for each tab each with it own distinct Query. I have each MasterLink pointing to the appropriate Master, either Table A or Table B and it doesn't work.
    I have tried to create additional Business components for the second view, but don't know how to link the rowset to the appropriate Business Component, if that's the problem.
    Any help or suggestion would be greatly appreciated, because I'm Lost.

    hi
    i've tried to do that some time ago and i had to give up... unfortunately i think java3D can't use various rendering modes for the same universe
    regards
    GnG

  • SQL to find highest version of multiple updated copies of rows

    Hello,
    I have an Archive table the stores archived versions of updated rows from the Main table. Each time a Main row is updated, a copy of it is copied to the Archive table with the next version number of a sequence.
    The Archive table has three columns: Title -- MessageId -- Version.
    Here is some sample data, showing three versions of messageid = 101 and two versions of messageid = 102:
    Title -- MessageId -- Version
    title abc -- 101 -- 1
    title xyz -- 101 -- 2
    title mno -- 101 -- 3
    title jkl -- 102 -- 1
    title opq -- 102 -- 2
    My goal is to do a query that might work like this:
    select title, messageid, max(version) from Archive group by title, messageid;
    -- so that I get this result set:
    title mno -- 101 -- 3
    title opq -- 102 -- 2
    Can somebody please me with the SQL to get this kind of result? Any suggestions are greatly appreciated.
    Thank you,
    Logan

    Here are two generic ways I think will work (haven't tried 'em):
    select title, messageid, version
    from archive
    where (messageid, version) in
      (select messageid, max(version)
       from archive
       group by messageid)
    select a.title, a.messageid, a.version
    from archive a,
      (select messageid, max(version) as max_version
       from archive
       group by messageid) b
    where a.messageid = b.messageid
       and a.version b.max_versionThere's probably a more efficient Oracle-specific way using the anaylytic functions, but I can't think of how to do it at the moment...

  • Extract function is returning multiple values in same row ...

    Hi i am using 11g Release2, 64 bit oracle database.
    Question is
    1)Below is the code i am using,
    WITH T AS (SELECT XMLTYPE('<ALL_REGIONS>
    <COUNTRY_CODE>
    <COUNTRY ID="001"/>
                   <COUNTRY ID="002"/>
                   <COUNTRY ID="003"/>
                   <COUNTRY ID="004"/>
                   <COUNTRY ID="005"/>
    </COUNTRY_CODE>               
    </ALL_REGIONS>') XMLCOL
    FROM DUAL)
    SELECT EXTRACT(VALUE(X),'/ALL_REGIONS/COUNTRY_CODE/COUNTRY/@ID') as "id" from t,TABLE(XMLSequence(extract(t.xmlcol,'/'))) x;
    2)Output is
    id
    001002003004005
    1 row selected.
    3)I need output to be like
    id
    001
    002
    003
    004
    005
    Can Anyone tell me how to do so, it's urgent ..... please mail to [email protected]

    Hi,
    Welcome to the forum!
    Can Anyone tell me how to do so, it's urgent ..... please mail to [email protected]
    We don't do "urgent" here, unless we're paid of course :)
    And since it's a community forum, it's preferred that the discussion takes place in the thread, not through personal mail, so that everyone can benefit from it.
    About your question, that's actually one of the most frequently asked around here, so I guess you could have found an answer with the search engine.
    There are even some similar questions (with solutions) on this page.
    This should work :
    SELECT extractValue(value(x),'/COUNTRY/@ID') as "id"
    FROM t,
         TABLE(
           XMLSequence(
             extract(t.xmlcol,'/ALL_REGIONS/COUNTRY_CODE/COUNTRY')
         ) x
    ;However, EXTRACT and XMLSequence functions are deprecated in your version.
    The recommended way is now :
    SELECT x.country_id
    FROM t,
         XMLTable('/ALL_REGIONS/COUNTRY_CODE/COUNTRY'
          passing t.xmlcol
          columns country_id varchar2(3) path '@ID'
         ) x
    ;

  • How to merge with multiple updates

    Hi All,
    can someone help with merge and multiple updates when matched ?
    create table foo
    id number,
    name varchar2(30),
    col1 date,
    col2 date
    create table bar
    id number,
    name varchar2(30),
    col1 date,
    col2 date
    insert into foo values ( 1, 'test1', sysdate + 30, sysdate);
    insert into foo values ( 2, 'test2', sysdate + 30, sysdate);
    insert into foo values ( 3, 'test3', sysdate + 30, sysdate);
    MERGE INTO BAR T1
    USING (SELECT id, NAME, col1, col2 FROM foo) T2
    ON (T1.id = T2.id)
    WHEN MATCHED THEN
    UPDATE SET T1.NAME=T2.NAME where T1.Name != T2.Name
    UPDATE SET T1.col1=T2.col1 where T1.col1 != T2.col1
    UPDATE SET T1.col2=T2.col2 where T1.col2 != T2.col2
    WHEN NOT MATCHED THEN
    INSERT (ID, NAME, col1, col2 ) VALUES (t2.Id, t2.NAME, t2.col1, t2.col2);
    Reason for having multiple updates to same row is i want to update the column only if name, col1, and col2 columns have changed. So, I want to first match by rows and then update the columns in bar that have changed in foo.
    Any thoughts on how I might do this in merge ?. I get the foll. error
    ERROR at line 6:
    ORA-00933: SQL command not properly ended
    Thanks
    Vissu

    I think you will be better off reading this link.
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_9016.htm#SQLRF01606
    It will be something like this.
    MERGE INTO BAR T1
    USING (SELECT id, NAME, col1, col2 FROM foo) T2
    ON (T1.id = T2.id)
    WHEN MATCHED THEN
    UPDATE SET T1.NAME=T2.NAME ,
                          t1.col1 = t2.col2 ,
                          t1.col2 = t2.col2
    where T1.Name != T2.Name or t1.col1 != T2.col1 or t1.col2 != t2.col2
    WHEN NOT MATCHED THEN
    INSERT (ID, NAME, col1, col2 ) VALUES (t2.Id, t2.NAME, t2.col1, t2.col2);Please note this code is untested.
    Regards
    Raj

  • Sql server if the row exist it update if the row new won't update

    I am
    working with Asp.net and C# and using SQl Server, I insert a row in one plase and works fine but when I try to update the same row it woudn't do anything, I
    try to update an existing row it works with the same code but not if I just
    insert new row.
    my code as
    below:
    String companyName = txCompany.Text.ToString();
    SqlConnection con =
    new
    SqlConnection(conString);
    SqlCommand cmd =
    new
    SqlCommand("INSERT
    INTO DocUp (CompanyName)VALUES (@CompanyName)", con);
    cmd.Parameters.AddWithValue("@CompanyName", companyName);
    try
    con.Open();
    cmd.ExecuteNonQuery();
    catch (Exception
    er)
    Response.Write("<script language='javascript'>alert('Connection Problem On Insert');</script>");
    finally
    con.Close();
    string strQuery =
    "UPDATE DocUp SET 
    QuoteFileName=@QuoteFileName, ContentType=@ContentType, QuoteFileData=@Data WHERE CompanyName=@Company";
    SqlCommand cmd =
    new
    SqlCommand(strQuery);
    cmd.Parameters.Add("@QuoteFileName",
    SqlDbType.VarChar).Value = filename;
    cmd.Parameters.Add("@ContentType",
    SqlDbType.VarChar).Value =
    "application/pdf";
    cmd.Parameters.Add("@Data",
    SqlDbType.Binary).Value = bytes;
    cmd.Parameters.Add("@Company",
    SqlDbType.VarChar).Value = companyName;
    InsertUpdateData(cmd);
    private
    Boolean InsertUpdateData(SqlCommand
    cmd)
    String strConnString = System.Configuration.ConfigurationManager
    .ConnectionStrings["S7V001_11022014ConnectionString1"].ConnectionString;
      SqlConnection con =
    new
    SqlConnection(strConnString);
    cmd.CommandType = CommandType.Text;
    cmd.Connection = con;
    try
    con.Open();
    cmd.ExecuteNonQuery();
    return
    true;
          catch (Exception
    ex)
    Response.Write(ex.Message);
    return
    false;
    finally
    con.Close();
    con.Dispose();

    Please use the  "Insert code block" button to insert *readable* code blocks 
    try{
    con.Open();
    cmd.ExecuteNonQuery();
    return true;
    You have not shared what query/functions that you are using to insert data. Please share. 
    Also it looks like more like a .Net related questions, (and if you agree,  ) I would recommend posting the question in .Net forum
    http://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=csharpgeneral
    Also I would recommend you to read "How to ask questions in Technical Forums" from the below link
    Satheesh
    My Blog |
    How to ask questions in technical forum

  • Two Infopath forms to submit or update the same sharepoint list

    Hi, I'm building a request SharePoint site so users can submit a request from a simplified InfoPath form (with only 5 out of 10 fields), but support personnel can open the form and then see all 10 fields.  For the list view, I know I can create custom
    views when user's see the list.  But when they open an item, I only want them to see the fields they entered and not the other fields the support personnel can see.  So I guess my question is: can I create two InfoPath forms to update one list or
    can I create an InfoPath form that has two views so one view suppresses fields and the other does not (based on permissions perhaps).

    Hi Darby,
    I would suggest creating two views, instead of two forms. Views can be shown/hidden based on the logged in users, takes few rules to configure based on the logged in users. you can also explore web service to get the users from groups to show/hide based
    on the user group, little overhead but give more control due to the fact of one single form.
    Two forms will be bit complex, if you want to update the same rows of information.
    here are some references -
    http://blogs.technet.com/b/anneste/archive/2011/11/02/how-to-create-an-infopath-form-to-auto-populate-data-in-sharepoint-2010.aspx
    http://claytoncobb.wordpress.com/2009/06/21/userprofileservice-extended/
    http://sharepoint911.com/blogs/laura/Lists/Posts/Post.aspx?List=daba3a3b%2Dc338%2D41d8%2Dbf52%2Dcd897d000cf3&ID=80&Web=dbb90e85%2Db54c%2D49f4%2D8e97%2D6d8258116ca0
    http://office.microsoft.com/en-us/infopath-help/add-delete-and-switch-views-pages-in-a-form-HA101732801.aspx
    Hope this helps!
    Ram - SharePoint Architect
    Blog - SharePointDeveloper.in
    Please vote or mark your question answered, if my reply helps you

  • Update multiple rows based on two columns in same row

    I have a 1000 rows in a table I would like to update with a unique value. This unique value is a cocatenation of two columns in teh same row.
    Each row has a (i) date and a (ii) time and a (iii) date_time column. I would like to update the date_time (iii) column with a cocatenation of the (i) date and (ii) time columns.
    I know how I would update a single row but how can I update multiple rows with a cocatenation of each of the two columns - i.e put a different value into the date_time column for each row?

    this?
    update table tab_name
    set date_time =date||time
    where your_condition

  • SQL Update a Single Row Multiple Times Using 2 Data Sets

    I'm working in tsql and have an issue where I need to do multiple updates to a single row based on multiple conditions. 
    By Rank_
    If the column is NULL I need it to update no matter what the Rank is.
    If the Ranks are the same I need it to update in order of T2_ID.
    And I need it to use the last updated output.
    I've tried using the update statement below but it only does the first update and the rest are ignored. Here is an example of the data sets i'm working w/ and the Desired results. Thanks in advance!
    update a
    set Middle = case when a.Rank_> b.Rank_ OR a.Middle IS NULL then ISNULL(b.Middle,a.Middle) end,
    LName = case when a.Rank_> b.Rank_ OR a.Lname IS NULL then ISNULL(b.LName,a.LName) end,
    Rank_ = case when a.Rank_> b.Rank_ then b.Rank_ end
    from #temp1 a
    inner join #temp2 b on a.fname = b.fname
    where b.T2_ID in (select top 100% T2_ID from #temp2 order by T2_ID asc)

    The Merge clause actually errors because it attempt to update the same record.  I think this CTE statement is the closest I've come but I'm still working through it as I'm not too familiar w/ them.  It returns multiple rows which I will have to
    insert into a temp table to update since the resulting row I need is the last in the table.
    ;WITH cteRowNumber
    AS(
    Select DISTINCT
    Row_Number() OVER(PARTITION BY a.LName ORDER BY a.LName ASC, a.Rank_ DESC,b.T2ID ASC) AS RowNumber
    ,a.FName
    ,a.LName
    ,b.LName as xLname
    ,a.MName
    ,b.MName AS xMName
    ,a.Rank_
    ,b.Rank_ AS xRank
    ,b.T2ID
    FROM #temp1 a
    inner join #temp2 b
    ON a.fname = b.fname
    ), cteCursor
    AS(
    Select a.RowNumber,
    a.Fname
    ,a.LName
    ,a.xLname
    ,a.MName
    ,a.xMName
    ,a.xRank
    ,a.T2ID
    ,CASE WHEN a.Rank_ >= a.xRank THEN ISNULL(a.xRank,a.Rank_) else ISNULL(a.Rank_,a.xRank) end AS Alt_Rank_
    ,CASE WHEN a.Rank_ >= a.xRank THEN ISNULL(a.xMName,a.MName) else ISNULL(a.MName,a.xMName) end AS Alt_MName
    ,CASE WHEN a.Rank_ >= a.xRank THEN ISNULL(a.xLName,a.lname) else ISNULL(a.LName,a.xlname) end as Alt_Lname
    FROM cteRowNumber a
    where a.RowNumber = 1
    UNION ALL
    Select crt.RowNumber
    ,crt.FName
    ,crt.LName
    ,crt.xLname
    ,crt.MName
    ,crt.xMName
    ,crt.xRank
    ,crt.T2ID
    ,CASE WHEN Prev.Alt_Rank_ >= crt.xRank THEN ISNULL(crt.xRank,Prev.Alt_Rank_) else ISNULL(Prev.Alt_Rank_,crt.xRank) end AS Alt_Rank
    ,CASE WHEN Prev.Alt_Rank_ >= crt.xRank THEN ISNULL(crt.xMName,Prev.Alt_MName) else ISNULL(Prev.Alt_MName,crt.xMName) end AS Alt_MName
    ,CASE WHEN Prev.Alt_Rank_ >= crt.xRank THEN ISNULL(crt.xLName,Prev.Alt_Lname) else ISNULL(Prev.Alt_Lname,crt.xLName) end as Alt_Lname
    FROM cteCursor prev
    inner join cteRowNumber crt
    on prev.fname = crt.fname and prev.RowNumber + 1 = crt.RowNumber
    SELECT cte.*
    FROM cteCursor cte

  • MULTIPLE UPDATES/INSERTIONS TO THE SAME TABLE

    How can I update/insert mutiple rows into the same table from one form ?

    Hi,
    Using the portal form on table you can insert only a single row. You can use master-detail form to insert multiple rows.
    Thanks,
    Sharmila

Maybe you are looking for