Deadlocks due to update statements

hi, we perform update statements as follows in the example below, with several threads each one mapping on a different connection as:
// THREAD operations
UPDATE table SET field=ThreadID WHERE field=default_value
COMMIT;
RESULTSET = SELECT pKey FROM table WHERE field=ThreadID;
... operations
// LOOP ON RESULTSET
WHILE RESULTSET.NEXT() NOT NULL;
UPDATE table SET field=default_Value WHERE PKEY=pKey;
COMMIT;
END WHILE;
// END LOOP
// END THREAD
Is a deadlock situation possible? Could this depend on particular settings of the configuration or connection?
Thanks a lot for the answers
null

hi aco,
deadlocks are possible only when you update a row (A)and not commit it and try to update a another row (B), and another process is trying to update row (B) and not commit and update row(A), so each process endup waiting for the other to release locks.
normally oracle does not let deadlocks in the database, if it detects deadlocks it rollbacks the statments itself with an error message.
since you seem to be commiting after an update there should not be a deadlock. unfortunately there are no settable parameters for lock issues. it is upto your application to prevent deadlocks. unless you use the facilities dbms_lock package or explicitly define your own locking mechanism for your application, you need not worry much about the deadlocks.
Mukundan.

Similar Messages

  • Deadlocks with simple UPDATE statement

    I have in a C# program a dictionary and in SQL Server a stored procedure with a simple UPDATE statement. I process the dictionary in parallel. For each entry in my dictionary I call this stored procedure and I am getting deadlocks.
    This is the UPDATE statement:
    ALTER PROCEDURE [dbo].[UpdateImages]
    @ICRTCode nvarchar(max),
    @ICRTImage nvarchar(max)
    AS
    BEGIN
    UPDATE Images SET processed = '1', Image = @ICRTImage, ProcessDate = GETDATE() WHERE IDICRT = @ICRTCode
    END
    Can someone give me a hint as to why this would cause deadlocks? There are no other processes writing to this table. This is a table in a staging database.

    http://blogs.msdn.com/bartd/archive/2006/09/09/747119.aspx
    http://blogs.msdn.com/bartd/archive/2006/09/25/770928.aspx
    Try change the statement a little bit
    UPDATE Images SET processed = '1', Image = @ICRTImage, ProcessDate = GETDATE()
    FROM
    Images
    WITH (TABLOCK) WHERE IDICRT = @ICRTCode
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • How to find username from trace file for deadlock due to user

    This is the info from the trace file.
    *** 2003-08-18 08:07:40.590
    *** SESSION ID:(560.60728) 2003-08-18 08:07:40.560
    DEADLOCK DETECTED
    Current SQL statement for this session:
    SELECT S.AVAILABLE,GET_AVAIL(S.PRODUCT_ID),S.ON_HAND,S.W_PL,S.PRODUCT_GROUP,S.SIZE_ID,S.COLOR_ID,S.ONEZ,S.COST,IS_IT_KIT(:b1),
    NVL(PR.R_AVAIL,0),NVL(PR.R_SOLD,0),NVL(PR.UNIT_OF_MEASURE,'QTY'),NVL(DECODE(PR.AV_CT,0,1,PR.AV_CT),1) FROM ACNTV.SKU S,ACNTV
    .PRERED_QUANTITIES PR WHERE S.PRODUCT_ID = PR.PRODUCT_ID (+) AND S.PRODUCT_ID = :b1 FOR UPDATE OF S.ON_HAND,
    S.W_PL,PR.R_AVAIL
    The following deadlock is not an ORACLE error. It is a
    deadlock due to user error in the design of an application
    or from issuing incorrect ad-hoc SQL. The following
    information may aid in determining the deadlock:
    Deadlock graph:
    ---------Blocker(s)-------- ---------Waiter(s)---------
    Resource Name process session holds waits process session holds waits
    TX-0021004b-000125d8 366 560 X 329 135 X
    TX-0008003b-000125fc 329 135 X 366 560 X
    session 560: DID 0001-016E-00000002 session 135: DID 0001-0149-00000002
    session 135: DID 0001-0149-00000002 session 560: DID 0001-016E-00000002
    Rows waited on:
    Session 135: obj - rowid = 00017FAC - AAAX+sAAPAAAS9/AAP
    Session 560: obj - rowid = 0001586C - AAAVhsABXAAAAIRAAN
    We know the objects ,but how to find out the username ?
    Thanks

    Hi;
    Please see:
    How To Check If a Profile Option Is Set In Oracle Application [ID 470102.1]
    How to list E-Business Suite Profile Option values for all levels using SQLPlus [ID 201945.1]
    How to Search all of the Profile Options for a Specific Value [ID 282382.1]
    Regard
    Helios

  • Snapshot isolation transaction aborted due to update conflict

    Hi Forum,
    Can anyone help me to give the solution for this below problem.
    We are developing MVC3 application with SQL Server 2008, we are facing as
    Snapshot isolation transaction aborted due to update conflict
    Snapshot isolation transaction aborted due to update conflict. You cannot use snapshot isolation to access table 'dbo.Tb_M_Print' directly or indirectly in database 'DB_Production' to update, delete, or insert the row that has been modified or deleted
    by another transaction. Retry the transaction or change the isolation level for the update/delete statement .
    Please tell me the solution how to proceed for the above problem
    Rama

    change the isolation level for the update/delete statement .
    The error message already mentions the solution.
    See also MSDN
    Lesson 1: Understanding the Available Transaction Isolation Levels => Update Conflicts
    Olaf Helper
    [ Blog] [ Xing] [ MVP]

  • Sql Update Statement (complex)

    Hi ,
    A very good morning to all.
    I am stuck in a problem , and i really hope for solutiion.
    I have a dimension table (DIM_CAR) for which i need to write a update statement.
    My table structure is :
    C_ID           Startdate                       EndDate
    7546343    2012-05-29 00:00:00    NULL
    7546343    2012-05-18 00:00:00    2012-05-29 00:00:00
    7546343    2012-05-14 00:00:00    2012-05-18 00:00:00
    7546343    2012-05-10 00:00:00    2012-05-10 00:00:00
    7546343    2012-05-10 00:00:00    2012-05-14 00:00:00
    7546343    2012-03-22 00:00:00    2012-03-22 00:00:00
    7546343    2012-03-15 00:00:00    2012-03-22 00:00:00
    7546343    2012-02-02 00:00:00    2012-03-15 00:00:00
    7546343    2012-01-31 00:00:00    2012-02-02 00:00:00
    Now the scenario is Whenever any update comes in car , then it closes the previous record and open a new record(SCD)
    For e.g the 1st update comes on 2012-02-02 , so it closes the last record (by putting 2012-02-02) in end date and open a new record by putting 2012-02-02 in startdate. Then update comes in 2012-03-15 and so on. The last record is for 2012-05-29 which is
    still open as there is no update after that,
    so whenever any update come it opens a new record with startdate value is extract date and enddate value NULL and closes the previous. Then  after another update , that NULL value is replace by the new date and another record opens.
    My prob is if you will closely analyse the dates , then there are some records missing in the above table due to which there are discrepencies in dates.
    E.g. If u see the 6th row, startdate is 2012-03-22 and enddate is also 2012-03-22. But here in this case the enddate should be 2012-05-10(which is next update)
    I need to write a sql script to update enddates with the latest update startdate in my table. I have 60000 of C_id which are affected.
    COULD ANYONE plz Help.. I knw its difficult but u can give a try ..........Plz ask if anyone requires more info.
    Abhishek

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
    use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. 
    This is minimal polite behavior on SQL forums. 
    >> I have a dimension table (DIM_CAR) for which I need to write a update statement. My table structure is : <<
    NO! This is a picture of the data; it is not DDL! Is this what you would have posted if you had manners? 
    CREATE TABLE Foobars
    (c_id CHAR(7) NOT NULL, 
     foo_start_date DATE NOT NULL, 
     PRIMARY KEY (c_id, foo_start_date), -- my guess!!
     CHECK (foo_start_date < foo_end_date),-- another guess! 
     foo_end_date DATE);
    INSERT INTO Foobar
    VALUES 
    ('7546343', '2012-05-29', 'NULL), 
    ('7546343', '2012-05-18', '2012-05-29'), 
    ('7546343', '2012-05-14', '2012-05-18'), 
    ('7546343', '2012-05-10', '2012-05-10'), 
    ('7546343', '2012-05-10', '2012-05-14'), 
    ('7546343', '2012-03-22', '2012-03-22'), 
    ('7546343', '2012-03-15', '2012-03-22'), 
    ('7546343', '2012-02-02', '2012-03-15'), 
    ('7546343', '2012-01-31', '2012-02-02');
    Now the scenario is Whenever any update comes in car, then it closes the previous record [sic: rows are not records! Please learn basic terms] and open a new record [sic](SCD). 
    What is “SCD” and why do you think it is meaningful to us? Here is an article on this topic. 
    Modifying Contiguous Time Periods
    This article explains how to modify contiguous time periods that were described in Joe Celko’s article 'Contiguous Time Periods in SQL'.  Joe describes the table itself that he calls the 'Kuznetsov History Table'. He explains how it is used to store contiguous
    time intervals with constraint to ensure that the date periods really are contiguous, The editor suggested that I give a brief description of how to modify the data in the History table as this may not be entirely obvious.
    When trusted constraints enforce data integrity, the data is guaranteed to be valid at the end of any statement, even if it is not committed. When we modify contiguous time periods, in order to get from one valid state to another we may need to insert a row
    and update another one, or we may need to delete a row and update another one. This is one of those cases when MERGE really shines – it allows us to get from one valid state to another in one statement, inserting, updating, and deleting rows as needed.
    CREATE TABLE Tasks
    (task_id INT NOT NULL, 
     task_score INTEGER NOT NULL, 
     current_start_date DATE NOT NULL, 
     current_end_date DATE NOT NULL, 
     previous_end_date DATE NULL, 
     CONSTRAINT PK_Tasks_task_id_current_end_date 
     PRIMARY KEY (task_id, current_end_date), 
     CONSTRAINT UNQ_Tasks_task_id_previous_end_date 
      UNIQUE (task_id, previous_end_date), 
     CONSTRAINT FK_Tasks_task_id_previous_end_date 
      FOREIGN KEY (task_id, previous_end_date) 
      REFERENCES Tasks (task_id, current_end_date), 
     CONSTRAINT CHK_Tasks_previous_end_date_NotAfter_current_start_date 
      CHECK (previous_end_date <= current_start_date), 
     CONSTRAINT CHK_Tasks_current_start_date_Before_current_end_date 
      CHECK (current_start_date < current_end_date)
    Some Easy Modifications.
    It is easy to begin a new series of time periods
    INSERT INTO Tasks
      (task_id, task_score, current_start_date, current_end_date, previous_end_date)
    VALUES (1, 100, '2010-1002', '2010-1023', NULL),
           (1, 80, '2010-1023', '2010-11-03', '2010-1023');  
     It is just as easy to continue adding periods to the end of the series.
    INSERT INTO Tasks
      (task_id, task_score, current_start_date, current_end_date, previous_end_date)
    VALUES(1, 98, '2010-11-20', '2010-11-25', '2010-11-03'),
          (1, 75, '2010-11-26', '2010-11-27', '2010-11-25');
    Deleting one or more rows from the end is just as easy, and we shall skip the example. As we have seen, it is easy to perform typical, the most common operations against history of periods.
    However, some other operations are less easy and need more explanations. Now that we have enough test data, let us move on to more complex examples. Here is the test data at this moment: 
    Adding periods to the beginning.
    Each series of periods has exactly one first period – this is enforced by the following constraint: Unique_task_id_and_previous_end_date
    As a result, when we are inserting one or more periods to the beginning of the series, we have to update the period that used to be the first, as follows:
    MERGE INTO Tasks 
    USING (VALUES (1, 98, '2009-03-01', '2009-03-06', NULL),
                  (1, 100, '2010-10-02', '2010-10-23', '2009-03-06') 
           ) AS Source (task_id, task_score, current_start_date, current_end_date, previous_end_date)
       ON Tasks.task_id = Source.task_id
           AND Tasks.current_start_date = Source.current_start_date
    WHEN MATCHED 
    THEN UPDATE
         SET task_score = Source.task_score, 
             current_start_date = Source.current_start_date, 
             current_end_date = Source.current_end_date, 
             previous_end_date = Source.previous_end_date
    WHEN NOT MATCHED 
    THEN INSERT (task_id, task_score, current_start_date, current_end_date, previous_end_date)
     VALUES (Source.task_id, Source.task_score, Source.current_start_date,
             Source.current_end_date, Source.previous_end_date); 
    Now we will verify that our test data looks as expected, with a new row at the beginning, and previous_end_date column is modified to point to the new row for the row that used to be the first before this modification:
    We are also going to discuss some other scenarios, such as adding/deleting periods in the middle of the series. In all these cases we shall be using MERGE, and the DML looks quite similar, so let us wrap it up in a stored procedure.
    CREATING A STORED PROCEDURE
    The following code implements this merging functionality with a stored procedure that uses a table to hold teh new rows:
    CREATE TABLE NewTasks
    (task_id INTEGER NOT NULL, 
    task_score INTEGER NOT NULL, 
    current_start_date DATE NOT NULL, 
    current_end_date DATE NOT NULL, 
    previous_end_date DATE NULL,
    deletion_flg CHAR(1));
    CREATE PROCEDURE MergeNewTasks
    AS BEGIN 
    MERGE INTO Tasks 
    USING (SELECT task_id, task_score, current_start_date, current_end_date, previous_end_date, deletion_flg
             FROM NewTasks) AS Source
       ON Tasks.task_id = Source.task_id
          AND Tasks.current_start_date = Source.current_start_date
    WHEN MATCHED AND deletion_flg = 'Y'
    THEN DELETE
    WHEN MATCHED 
    THEN UPDATE SET
         task_score = Source.task_score, 
         current_start_date = Source.current_start_date, 
         current_end_date = Source.current_end_date, 
         previous_end_date = Source.previous_end_date
    WHEN NOT MATCHED 
    THEN INSERT (task_id, task_score, current_start_date, current_end_date, previous_end_date) 
     VALUES (Source.task_id, Source.task_score, Source.current_start_date, Source.current_end_date, Source.previous_end_date);
    END; 
    Let us use this stored procedure.
    Filling a gap in the middle of the series
    The following code fills the gap on November 25th.
    CREATE TABLE NewTasks (..);
    INSERT INTO NewTasks
      (task_id, task_score, current_start_date, current_end_date, previous_end_date, deletion_flg)
    VALUES (1, 75, '2010-11-25', '2010-11-26', '2010-11-25', 'N'),
     (1, 80, '2010-11-26', '2010-11-27', '2010-11-26', 'N');
    EXEC MergeNewTasks NewTasks = NewTasks;  
    Here is the data after this modification, with a period added in the middle fo the series:
    Deleting a period in the middle of the series
    The following code deletes the period added in the previous example.
    CREATE TABLE NewTasks (..);
    INSERT INTO NewTasks
      (task_id, task_score, current_start_date, current_end_date, 
        previous_end_date, deletion_flg)
    VALUES (1, 75, '2010-11-25', '2010-11-26', '2010-11-25', 'Y'),
           (1, 80, '2010-11-26', '2010-11-27', '2010-11-25', 'N');
    EXEC MergeNewTasks;  
    Here is the data after this modification:
    Inserting two periods in the middle, and adjusting an exaisting period to make room for them. This is the last and most complex example involving our stored procedure:
    CREATE TABLE NewTasks (..);
    INSERT INTO NewTasks
      (task_id, task_score, current_start_date, current_end_date, previous_end_date, deletion_flg)
    VALUES (1, 98, '2010-11-20', '2010-11-22', '2010-11-03', 'N'), 
           (1, 75, '2010-11-22', '2010-11-23', '2010-11-22', 'N'),
           (1, 98, '2010-11-23', '2010-11-25', '2010-11-23', 'N');
    EXEC MergeNewTasks; 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • How to use escape character in update statement.

    Hi All,
    I'm trying to update table using following sql update statement, but everytime it's asking me for the input due to the '&' value in below sql.
    UPDATE xyz_xyz
       SET NAME = 'ABC & PQR'
    WHERE ID = (SELECT ID
                   FROM abc_abc
                  WHERE NAME = 'C & PQR');Please let me know how to use escape character syntax or let me know if there is any alternative solution.
    Thanks,
    Vishwas

    Hi,
    By default, & marks a substitution variable name.
    If you're not using substitution variables in that statement (or, if this is in PL/SQL, in that entire package or procedure) then the easiest thing to do is just diable substitution variables; then & will be a normal character:
    SELECT  DEFINE  OFF
    UPDATE xyz_xyz
       SET NAME = 'ABC & PQR'
    WHERE ID = (SELECT ID
                   FROM abc_abc
                  WHERE NAME = 'C & PQR');
    SET  DEFINE  ONIf you can't do that, then & is always taken literally if it comes right before a single-quote, so you could say:
    UPDATE xyz_xyz
       SET NAME = 'ABC &' || ' PQR'
    WHERE ID = (SELECT ID
                   FROM abc_abc
                  WHERE NAME = 'C &' || ' PQR');There is a SQL*Plus "SET ESCAPE" command, too, but if you use it, you have to worry about whether the escape character is to be taken literally or not.
    SET   ESCAPE  \Yet another alternative is to make some other character, such as ~, mark the substitution variables:
    SET  DEFINE  ~Read all about them in the SQL*Plus manual.
    http://download.oracle.com/docs/cd/B28359_01/server.111/b31189/ch2.htm#sthref103

  • Using Escape character in UPDATE statement

    SELECT REPLACE
              ( REPLACE
                     ( REPLACE( REPLACE( REPLACE( REPLACE( BODY, '<STARTOFLINK>' )
                                                , '<ENDOFLINK>' )
      FROM ARTICLEI need to use the above in an UPDATE statement to remove some HTML tags from a CLOB column. However when I run the script it asks for the substitution variables for the '&' characters. I've tried "ESCAPE '\'" but I think you can only use that with a like operand.
    Any suggestions?
    Message was edited by:
    Terrible
    As you can see the HTML tags have been converted in this post!! I'm trying to remove:
    & amp;
    & quot;
    & ndash;
    & #039;

    This may help;
    SQL> create table t (col1 varchar2(200))
    Table created.
    SQL> insert into t values('<STARTOFLINK>')
    PL/SQL executed.
    SQL> insert into t values('<ENDOFLINK>')
    PL/SQL executed.
    SQL> insert into t values(chr(38) || 'amp;')
    PL/SQL executed.
    SQL> insert into t values(chr(38) || 'quot;')
    PL/SQL executed.
    SQL> insert into t values(chr(38) || 'ndash;')
    PL/SQL executed.
    SQL> insert into t values(chr(38) || '#039;')
    PL/SQL executed.
    SQL> insert into t values('<STARTOFLINK>link<ENDOFLINK> '
                       || '  AMP:' || chr(38) || 'amp;'
                       || '  DQT:' || chr(38) || 'quot;'
                       || '  DASH:'|| chr(38) || 'ndash;'
                       || '  SQT:' || chr(38) || '#039;')
    PL/SQL executed.
    SQL> select * from t
    col1                                                                           
    <STARTOFLINK>                                                                  
    <ENDOFLINK>                                                                    
    <STARTOFLINK>link<ENDOFLINK>   AMP:&  DQT:"  DASH:–  SQT:' 
    7 rows selected.
    SQL> select regexp_replace(
              regexp_replace(
                 regexp_replace(
                    regexp_replace(
                       regexp_replace(col1, '<.*OFLINK>',NULL),
                    chr(38) || 'amp;', chr(38)),
                 chr(38) || 'quot;', chr(34)),
              chr(38) || 'ndash;', chr(45)),
           chr(38) || '#039;', chr(39))
    new_col from t
    NEW_COL                                                                        
       AMP:&  DQT:"  DASH:-  SQT:'                                                 
    7 rows selected.Message was edited by:
    MScallion
    The SELECT * values were not as they are displayed due to HTML conversions.

  • Replication update statement takes long time

    Hi Replication experts,
    I have a issue and please suggest if my understanding and solution is correct.
    We have a transactional replication setup for data warehouse, from today morning replication got huge latency so when I looked into it I saw the "sp_MSupd_< tablename >" was running for very long time and by this time it was running for 9 hours
    still no data was updated, Latency went very high. What we feel is that the index maintenance was not done in subscriber also it was not replicated too. So due to high fragmentation the update statement could take very long.
    As there was no error message or blocks found all we see is the update taking very long. So to avoid this we are planning to remove the index, as this is just data warehouse index maintenance is not required by removing we can gain some space too. Is this a
    good Idea to implement?
    When we ran profiler nothing was found, no error or alert logged.
    Please let me know your suggestions
    Thanks
    Best Regards Moug

    Hi All,
    The Issue we found to be is that a day before, new column was added to the table and 9000 rows were updated ... This caused the distributor to slow down the update operation as the index in subscriber(15 million rows) was updating every time  a row
    is updated.. So we suspect that adding a new column and updating it at the same time is the culprit..
    But still am not convinced as per my understanding the distributor operates by comparing the primary key of publisher that was changed with the primary key of the subscriber and apply those change.. If that is the case why should it worry about the new column
    added or the number of updates..
    Also one strange thing is another table was also lagging behind in its operation ,though that table was updated with just 18 rows.. So in a nutshell the update operation was totally down by distributor operation on that day..
    Can someone please shed some light on this, Replication is my favorite topic but now I got fear of it.. after failing to know what could be issue... 
    Best Regards Moug

  • Problem with CFQUERY update statement

    I'm having trouble getting an SQL Update statement to work
    correctly and I'm scratching my head as to why.
    The output i get is the following:
    Syntax error in UPDATE statement
    SQLSTATE 42000
    SQL UPDATE companies SET CompanyName = 'Insight Data Ltd',
    Address1 = '5 Boulevard', Address2 = '', Address3 = '', City =
    'Weston-super-Mare', County = 'North Somerset', Postcode =
    'BS231NN', OfficeBranch = 'BR', contacttitle1 = 'Mr', contactname1
    = 'Andrew', contactsurname1 = 'Scott', contactposition1 = 'Owner',
    mail1 = 'yes', TelNumber = '01934 123456', TPS = 'no', FaxNumber =
    '',FPS = 'no',MobileNumber = '',MPS = 'no',email =
    '[email protected]', EPS = 'no', WebAddress = '
    http://www.insightdata.co.uk',
    contacttitle2 = 'Mr', contactname2 = 'David', contactsurname2 =
    'Lewis', contactposition2 = 'Office Manager', mail2 = 'no',
    contacttitle3 = 'Mr', contactname3 = '', contactsurname3 = '',
    contactposition3 = 'Owner', mail3 = 'no', contacttitle4 = 'Mr',
    contactname4 = '', contactsurname4 = '', contactposition4 =
    'Owner', mail4 = 'no', wPVCUfab = 'yes', wALUinst = 'yes', WHERE
    companyid = 33415
    VENDORERRORCODE -3503
    DATASOURCE idv6
    I've checked that all the data fields are in the correct
    format, and I can't see why I am getting a syntax error. Any help
    on this would be appriciated

    Agreed, but it looks like you already have the sql. Take the
    query from the error message above and run it in your database.
    Though I did notice have an extra comma between the last column and
    there WHERE clause.
    wALUinst = 'yes' , WHERE companyid = 33415
    For the optional columns, put the commas first to prevent
    errors due to trailing or too many commas
    UPDATE Table
    SET Column1 = 'value'
    <cfif SomeValueExists>, Column2 = 'other value'
    </cfif>
    WHERE ID = 123
    Two other things to consider: use cfqueryparam and consider
    normalizing your table. Column names like Contact1, Contact2,
    Contact3 ... are usually a sign its time to normalize.

  • Update Statement With Decode and Business Dates

    Hello everyone,
    I need to write a UPDATE statement using business date rule. In general, the due date is 30 days from the checkout date. If the due date falls on a Saturday or Sunday then the loan period is 32 days.
    I know that to test for a weekday, I'd need to use the to_char function in Oracle with the format of ‘D’. I did some research and found that to test which weekday November 12, 2007 falls on, I'd need to use the expression to_char(’12-NOV-2007’,’D’). This function returns a number between 1 and 7. 1 represents Sunday, 2 Monday, …,7 Saturday.
    What I really would need to do is write one UPDATE statement using an expression with the Decode function and the to_Char function:
    UPDATE book_trans SET due_dte = expression
    These are the transactions that will need to be updated:
    ISBN 0-07-225790-3 checked out on 15-NOV-2007 by employee 101(book_trans_id=1)
    ISBN 0-07-225790-3 checked out on 12-NOV-2007 by employee 151(book_trans_id=2)
    ISBN 0-201-69471-9 checked out on 14-NOV-2007 by employee 175(book_trans_id=3)
    ISBN 0-12-369379-9 checked out on 16-NOV-2007 by employee 201(book_trans_id=4)
    I manually calculated the due-dte and wrote update statement for each book_trans_id:
    UPDATE book_trans SET due_dte = '17-dec-07' WHERE book_trans_id = 1;
    UPDATE book_trans SET due_dte = '12-dec-07' WHERE book_trans_id = 2;
    UPDATE book_trans SET due_dte = '14-dec-07' WHERE book_trans_id = 3;
    UPDATE book_trans SET due_dte = '18-dec-07' WHERE book_trans_id = 4;
    As you can see, it's very cumbersome and I'd just like to know how to incorporate everything in one Update statement:
    UPDATE book_trans SET due_dte = expression
    so that if due date falls on Saturday or Sunday, the loan period is 32 days; weekday, loan period is 30 days.
    Any tips or help will be greatly appreciated. Thanks!

    Hi,
    882300 wrote:
    Hello everyone,
    I need to write a UPDATE statement using business date rule. In general, the due date is 30 days from the checkout date. If the due date falls on a Saturday or Sunday then the loan period is 32 days. That's equivalent to saying that the due date is normally 30 days after the checkout date, but if the checkout date falls on a Thursday or Friday, then the due date is 32 days after the checkout date. I used this equivalent in the statement below.
    I know that to test for a weekday, I'd need to use the to_char function in Oracle with the format of ‘D’. I did some research and found that to test which weekday November 12, 2007 falls on, I'd need to use the expression to_char(’12-NOV-2007’,’D’). This function returns a number between 1 and 7. 1 represents Sunday, 2 Monday, …,7 Saturday.That's just one way to find out the weekday, and it's error-prone because it depends on your NLS_TERRITORY setting. A more reliable way is to use 'DY' or 'DAY' as the 2nd argument to TO_CHAR. That depends on NLS_DATE_LANGUAGE, but you can explicitly set the language in the optional 3rd argument to TO_CHAR, which means your code will work the same no matter what the NLS settings happen to be. It's also easier to debug: you may have to think whether '1' means Sunday or Monday, but it's easy to remember that 'SUN' means Sunday.
    What I really would need to do is write one UPDATE statement using an expression with the Decode function and the to_Char function:
    UPDATE book_trans SET due_dte = expressionHere's one way:
    UPDATE  book_trans
    SET     due_dte = checkout_dte + CASE
                                      WHEN  TO_CHAR ( checkout_dte
                                             , 'fmDAY'
                                     , 'NLS_DATE_LANGUAGE=ENGLISH'
                                     ) IN ('THURSDAY', 'FRIDAY')
                             THEN  32
                             ELSE  30
                                  END
    WHERE   book_trans_id      IN (1, 2, 3, 4)
    ;This assumes that checkout date is a column in the same table.

  • Is there any System setting for Update statement

    Is there any setting for update statement related to implicit commit because Update statement in my code behaves differently in different systems.
    My code is
    Data:  it_eaus like eaus occurs 0 with header line,
            wa_eaus type eaus.
    select * from eaus into table it_eaus where auszbeleg = '000000000001'  and storausz = 'X'.
    if sy-subrc = 0 .
    wa_eaus-aedat = ''.
    wa_eaus-aenam = ''.
    wa_eaus-storausz = ''.
    modify it_eaus from wa_eaus transporting aedat aenam storausz where auszbeleg = '000000000001'.
    update eaus from table it_eaus.
    endif.
    Data:  it_eausv like eausv occurs 0 with header line,
            wa_eausv type eausv.
    select * from eausv into table it_eausv where auszbeleg = '000000000001'  and storausz = 'X'.
    if sy-subrc = 0 .
    wa_eausv-aedat = ''.
    wa_eausv-aenam = ''.
    wa_eausv-storausz = ''.
    modify it_eausv from wa_eausv transporting aedat aenam storausz where auszbeleg = '000000000001'.
    update eausv from table it_eausv.
    endif.

    Hi
    It isn't an alternative way: u can only explicit the COMMIT just as I said before:
    Update DBTAB set COL.
    COMMIT WORK.
    Anyway just I said before the debugger can execute a COMMIT, from SAP help:
    The New Debugger can run in exclusive and non-exclusive mode. Exclusive mode means that the application that is being analyzed exclusively occupies a work process of the application server during debugging. In non-exclusive mode, the Debugger functions are limited. In non-exclusive mode, after each Debugger interaction, the system requests a roll-out in the application. Therefore, an implicit database commit must be executed. This has the following consequences:
    u25CF      Debugging is not possible between the statements SELECTand ENDSELECTbecause the database cursor needs to be closed when using an implicit database COMMIT statement.
    In this case, program execution is terminated.
    ·        Debugging is not possible for conversion or field exits.
    ·        Due to the implicit database commit, inconsistent datasets can occur in the database.
    For this reason, non-exclusive mode is not possible in productive systems.
    Max

  • Errors while running BPEL and incorrect UPDATE statement

    Hi,
    I installed following software.
    1. Oracle Database 10g Release 2
    2. SOA Suite 10g Release 3
    3. Oracle JDeveloper (10.1.3.4)
    I developed a BPEL process to lock a userid in PeopleSoft.
    I have two issues.
    a) I am getting error as shown below
    b) its generating incorrect UPDATE statement, even though its assigning correct values in XML (UPDATE PSOPRDEFN SET LASTUPDOPRID = ?, OPRID = ? WHERE (ACCTLOCK = ?) i.e instead of setting OPRID in where clause its setting ACCTLOCK in where clause
    <messages><input><Invoke_1_update_InputVariable><part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PsoprdefnCollection"><PsoprdefnCollection xmlns="http://xmlns.oracle.com/pcbpel/adapter/db/top/UpdateUserProfile">
    <Psoprdefn>
    <oprid>snagulapalli</oprid>
    <version/>
    <oprdefndesc/>
    <emplid/>
    <emailid/>
    <oprclass/>
    <rowsecclass/>
    <operpswd/>
    <encrypted/>
    <symbolicid/>
    <languageCd/>
    <multilang/>
    <currencyCd/>
    <lastpswdchange/>
    <acctlock>1</acctlock>
    <prcsprflcls/>
    <defaultnavhp/>
    <failedlogins/>
    <expent/>
    <oprtype/>
    <useridalias/>
    <lastsignondttm/>
    <lastupddttm/>
    <lastupdoprid>Laptop BPEL</lastupdoprid>
    <ptallowswitchuser/>
    </Psoprdefn>
    </PsoprdefnCollection>
    </part></Invoke_1_update_InputVariable></input><fault><remoteFault xmlns="http://schemas.oracle.com/bpel/extension"><part name="code"><code>17002</code>
    </part><part name="summary"><summary>file:/D:/product/10.1.3.1/OracleAS_1/bpel/domains/default/tmp/.bpel_Sandbox_9.0_882edce22e996c64b48ea25cbe023033.tmp/Update_User_Profile.wsdl Update_User_Profile_ptt::update(PsoprdefnCollection) - WSIF JCA Execute of operation 'update' failed due to: DBWriteInteractionSpec Execute Failed Exception.
    update failed. Descriptor name: http://UpdateUserProfile.Psoprdefn. Caused by: Io exception: Connection reset by peer: socket write error
    ; nested exception is:
    ORABPEL-11616
    DBWriteInteractionSpec Execute Failed Exception.
    update failed. Descriptor name: http://UpdateUserProfile.Psoprdefn. Caused by: Io exception: Connection reset by peer: socket write error
    Caused by Exception TOPLINK-4002 (Oracle TopLink - 10g Release 3 (10.1.3.1.0) (Build 061004)): oracle.toplink.exceptions.DatabaseException
    Internal Exception: java.sql.SQLException: Io exception: Connection reset by peer: socket write errorError Code: 17002
    Call:UPDATE PSOPRDEFN SET LASTUPDOPRID = ?, OPRID = ? WHERE (ACCTLOCK = ?)
    bind => Laptop BPEL, snagulapalli, 1
    Query:UpdateObjectQuery(<Psoprdefn 1 />).
    </summary>
    </part><part name="detail"><detail>
    Internal Exception: java.sql.SQLException: Io exception: Connection reset by peer: socket write errorError Code: 17002
    Call:UPDATE PSOPRDEFN SET LASTUPDOPRID = ?, OPRID = ? WHERE (ACCTLOCK = ?)
    bind => Laptop BPEL, snagulapalli, 1
    Query:UpdateObjectQuery(<Psoprdefn 1 />)</detail>
    </part></remoteFault></fault></messages>
    Regards,
    Shanti Nagulapalli.

    What version of SOA Suite are you using, SOA Suite 10g Release 3 is not enough information. Make sure that it is the same as your JDev version if it isn't then either downgrade the JDev or upgrade the SOA Suite.
    If you are still on SOA 10.1.3.1 then I would upgrade as there are many bugs in this release.
    These kind of strange errors are generally caused by incompatibility between design time (JDev) and run time (SOA Suite)
    cheers
    James

  • Operation is no valid due to current state of object.

    I have created a web part. And in that web part I have a link which refer to a page in share point with query string.
    Some thing like as :
    <a href=http://sharepoint:79/codelibrary/PageName.aspx?Id=1/>
    It gives the error that Operation is not valid due to current state of object.
    But when I call this page with out Id=1 or without any query string, it works fine.
    Please help me, where I am doing wrong.
    Many Thanks

    Hi Naeem,
    Thanks for posting your query, Kindly Do NOT call .Update() inside Evelvated Permission’s delegate Just do it below SPSecurity.RunWithElevatedPrivileges
    Also, Check out the detail for more details in below mentioned URL
    http://blogs.msdn.com/b/suresh/archive/2014/08/26/getting-quot-operation-is-not-valid-due-to-the-current-state-of-the-object-quot-error.aspx
    I hope this is helpful to you. If this works, Please mark it as Answered.
    Regards,
    Dharmendra Singh (MCPD-EA | MCTS)
    Blog : http://sharepoint-community.net/profile/DharmendraSingh

  • About getting a wrong plan due to incorrect stats

    Hi,
    can someone give an example which demonstrate how wrong stats on a table lead to a different/inefficient execution plan? I tried one but in what I tried, optimizer picked same plan when stats were incorrect. What I tried was to have a table with two columns and an index on one column and select based on this column as below:
    SQL> desc tab1
    Name Null? Type
    COL1 NOT NULL NUMBER
    COL2 NUMBER
    (there is an index i1 on table col1)
    SQL> select num_rows from user_tables where table_name=
    2 'TAB1';
    NUM_ROWS
    0
    SQL> select count(*) from tab1;
    COUNT(*)
    10000
    SQL> set autot on
    SQL> select * from tab1 where col1=58398;
    no rows selected
    Execution Plan
    Plan hash value: 4092115641
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
    |
    | 0 | SELECT STATEMENT | | 1 | 26 | 1 (0)| 00:00:
    01 |
    | 1 | TABLE ACCESS BY INDEX ROWID| TAB1 | 1 | 26 | 1 (0)| 00:00: <---oracle uses index when stats are not updated
    01 |
    |* 2 | INDEX RANGE SCAN | I1 | 1 | | 1 (0)| 00:00:
    01 |
    Predicate Information (identified by operation id):
    2 - access("COL1"=58398)
    Statistics
    0 recursive calls
    0 db block gets
    2 consistent gets
    0 physical reads
    0 redo size
    289 bytes sent via SQL*Net to client
    327 bytes received via SQL*Net from client
    1 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    0 rows processed
    --now update stats
    SQL> exec dbms_stats.gather_table_stats(null,tabname=>'TAB1',cascade=>true);
    PL/SQL procedure successfully completed.
    SQL> select * from tab1 where col1=58398;
    no rows selected
    Execution Plan
    Plan hash value: 4092115641
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
    |
    | 0 | SELECT STATEMENT | | 1 | 7 | 2 (0)| 00:00:
    01 |
    | 1 | TABLE ACCESS BY INDEX ROWID| TAB1 | 1 | 7 | 2 (0)| 00:00: <--same plan of acess by index row id)
    01 |
    |* 2 | INDEX RANGE SCAN | I1 | 1 | | 1 (0)| 00:00:
    01 |
    Predicate Information (identified by operation id):
    2 - access("COL1"=58398)
    Statistics
    0 recursive calls
    0 db block gets
    2 consistent gets
    0 physical reads
    0 redo size
    289 bytes sent via SQL*Net to client
    327 bytes received via SQL*Net from client
    1 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    0 rows processed
    SQL>
    In the example I tried, oracle picks the same plan whether stats are updated or not - I am trying to get one example where oracle picks wrong plan (due to incorrect stats).
    thanks

    It doesn't matter whether or not you have the cheapest or most expensive voice and text plants, smartphones require a data plan to be eligible for a discount. It should be the same for the iPhone 4.
    As for any work discount, I don't think you need to do anything to continue to receive it. I receive a discount for working with the government and I didn't need to do anything when I changed my plan a couple of times before.

  • Rollback from update statement

    Hello folks,
    I am using oracle 10G.
    Just before sometime I have fired one Update statement (without where clause) Due to this all the records in the table have been modified. also I have disconnected from this session :(
    Is there any way to rollback this work ?
    (please note that I do not have database backup with me right now.. there is long process to reload the
    original data from table from backup)

    This method is old which is used on 9i but i think you can also used it in 10g
    DECLARE
    CURSOR cur_item_mst is
         SELECT * FROM item_master;
    v_row_item_mst item_master%ROWTYPE;
    BEGIN
         Dbms_flashback.enable_at_time(TO_TIMESTAMP ('22-SEP-2008 13:00:00','DD-MON-YYYY HH24:MI:SS'));
         Open cur_item_mst;
         Dbms_flashback.disable;
         Loop
              Fetch cur_item_mst INTO v_row_item_mst;
              Exit when cur_item_mst%NOTFOUND;
              INSERT INTO item_master VALUES (
                   v_row_item_mst.itemno,
                   v_row_item_mst.description,
                   v_row_item_mst.rate);
         END LOOP;
         CLOSE cur_item_mst;
         COMMIT;
    END;
    / If is all dependent on the size of undo_retension parameter for how long the undo is saved.
    Please change the time & date according to your requirnment.
    Regards
    Singh
    Edited by: Singh on Sep 22, 2008 3:56 PM

Maybe you are looking for

  • How do you know if you need a new iPod touch battery

    Ok so a couple of days ago I put my ipod on the charger and it was charging but itwas starting to get really hot so I just disconnected it. When i disconnectd it it was fully charged but when i went to go use it it was only 2% left so i just it die (

  • Changing screen resolution with a button

    Hi, I would like to ask if there is a way for an interface to change the screen resolution of the computer? I am wanting to build an interface that loads an interactive camera that works with processing however I am needing it to be at the resolution

  • ISight With Windows?

    I recently sold my iMac G4, and my Uncle had purchased and sent me an iSight for my Mac for my birthday. I am back on my Dell Dimension, and I was wondering if I bought the 6-pin FireWire port card, if iSight will work with Windows as a webcam and a

  • Failed to save scale setting

    I tried to increase the number of instances for an Azure WebApp (DNN website) from one to two. I got the following error: Failed to save scale setting. Not enough available reserved instance servers to satisfy this request. Currently 0 instances are

  • How to update Purchase Schedule agreement

    Hi Experts,        Please tell me the ,is there any Function Module/BAPI which updates Purchase Schedule Agreement(Transaction Code ME38) in SAP??? Thanks.. Debi.