ExecuteBatch(): number of successfully updated rows

Hello everybody:
Here is a simple but often a repeated question in java forums:
Requirement:
1.To read a flat file that has many rows of data.
2.Parse the data and update the database accordingly.
3.Find the number of successfully updated rows.
Approach:
After reading the file and parsing its data,
- use PreparedStatement
- use executeBatch()
I found this as unadvisable to use executeBatch() as its implementation is
inherently driver specific. The executeBatch() returns an array of update counts.
Now,can any one tell me, what is the best way to trace the number of successfully
(and unsuccessfully) updated rows by using this count?
Is there any other way to achieve the same by not using executeBatch()?
Can any one share a snippet of code to achieve this specific functionality?
[Need is to log the number of unsuccessful attempts along with their
corresponding rows of data].
Thanks & regards,
Venkat Kosigi

executeBatch submits a batch of commands to the database for execution and if all commands execute successfully, returns an array of update counts. The int elements of the array that is returned are ordered to correspond to the commands in the batch, which are ordered according to the order in which they were added to the batch. The elements in the array returned by the method executeBatch may be one of the following:
-- A number greater than or equal to zero indicates that the command was processed successfully and is an update count giving the number of rows in the database that were affected by the command's execution
-- A value of -2 indicates that the command was processed successfully but that the number of rows affected is unknown
If one of the commands in a batch update fails to execute properly, this method throws a BatchUpdateException, and a JDBC driver may or may not continue to process the remaining commands in the batch. However, the driver's behavior must be consistent with a particular DBMS, either always continuing to process commands or never continuing to process commands.
If the driver continues processing after a failure, the array returned by the method BatchUpdateException.getUpdateCounts will contain as many elements as there are commands in the batch, and at least one of the elements will be the following:
-- A value of -3 indicates that the command failed to execute successfully and occurs only if a driver continues to process commands after a command fails.
return values have been modified in the Java 2 SDK, Standard Edition, version 1.3 to accommodate the option of continuing to proccess commands in a batch update after a BatchUpdateException obejct has been thrown.
Throws BatchUpdateException (a subclass of SQLException) if one of the commands sent to the database fails to execute properly or attempts to return a result set. The BatchUpdateException getUpdateCounts() method allows you to known the element who caused the fail identified by a -3 value.
-- So, if you have a succesfully result, look for at the executeBatch returned array ( #values >= 0 ) + ( #values == -2 ) = successes
and if you have not a succesfully result, catching the BatchUpdateException take the array returned by the getUpdateCounts() method, and look for the position in which array values are -3. You could take the data at this position on batch and log it.
-- Other way to insert a bulk copy on database is to use a bcp command ( it�s not java, bcp is an independent command ) that allows you to do bulk inserts from file, indicate an error file, bcp will give to you as result a file with those lines not where inserted.
I hope have help you.;)

Similar Messages

  • Count of updated rows

    Hi there,
    I would like to be able to count updated rows after submitting a page. I'm aware that #MRU_COUNT# does that in success messages, but I don't know how to (or is it even possible) assign that value to a page item, for instance.
    (The number of updated rows isn't all that important, I would just like to know if there was a change made or not).
    Any help is much appreciated!
    Edited by: 893204 on Oct 25, 2011 2:40 PM

    Hi, Chris, thank you for your reply.
    I have a report on Employees (Automated Row Fetch).
    Editing a row brings up a modal window where I can change employee name, address and so on. I want to be able to know was there any change made to the row when the user clicks Submit.
    I hope I made things clearer this time.

  • Cursor and Update rows based on value/date

    SQL Server 2012
    Microsoft SQL Server Management Studio
    11.0.3128.0
    Microsoft Analysis Services Client Tools
    11.0.3128.0
    Microsoft Data Access Components (MDAC)
    6.1.7601.17514
    Microsoft MSXML 3.0 4.0 5.0 6.0 
    Microsoft Internet Explorer
    9.11.9600.16518
    Microsoft .NET Framework
    4.0.30319.18408
    Operating System
    6.1.7601
    The objective of this is to test the Cursor and use it on a production environment after this is fixed. What I would like to do is update rows in a column i duplicated originally called 'HiredDate' from AdventureWorks2012 HumanResources.Employee table. I
    made a duplicate column called 'DateToChange' and would like to change it based on a date I have picked, which returns normally 2 results (i.e. date is '04/07/2003'). The code runs but will not change both dates. It did run however with an error but changed
    only 1 of the 2 rows because it said ['nothing available in next fetch'].
    The code to add the columns and perform the query to get the results I am running this against:
    -- ADD column 'DateToChange'
    ALTER TABLE [HumanResources].[Employee] ADD DateToChange Date NOT NULL;
    -- Copy 'HireDate' data to 'DateToChange'
    UPDATE HumanResources.Employee SET DateToChange = HireDate;
    -- Change 'DateToChange' to NOT NULL
    ALTER TABLE [HumanResources].[Employee] ALTER COLUMN DateToChange Date NOT NULL;
    SELECT BusinessEntityID,HireDate, CONVERT( char(10),[DateToChange],101) AS [Formatted Hire Date]
    FROM HumanResources.Employee
    WHERE [DateToChange] = '04/07/2003';
    Code:
    USE AdventureWorks2012;
    GO
    -- Holds output of the CURSOR
    DECLARE @EmployeeID INT
    DECLARE @HiredDate DATETIME
    DECLARE @HiredModified DATETIME
    DECLARE @ChangeDateTo DATETIME
    --Declare cursor
    -- SCROLL CURSOR ALLOWS "for extra options" to pul multiple records: i.e. PRIOR, ABSOLUTE ##, RELATIVE ##
    DECLARE TestCursor CURSOR SCROLL FOR
    -- SELECT statement of what records going to be used by CURSOR
    -- Assign the query to the cursor.
    SELECT /*HumanResources.Employee.BusinessEntityID, HumanResources.Employee.HireDate,*/ CONVERT( char(10),[DateToChange],101) AS [Formatted Hire Date]
    FROM HumanResources.Employee
    WHERE DateToChange = '01/01/1901'
    /*ORDER BY HireDate DESC*/ FOR UPDATE OF [DateToChange];
    -- Initiate CURSOR and load records
    OPEN TestCursor
    -- Get first row from query
    FETCH NEXT FROM TestCursor
    INTO @HiredModified
    -- Logic to tell the Cursor while "@@FETCH_STATUS" 0 the cursor has successfully fetched the next record.
    WHILE (@@FETCH_STATUS = 0 AND @@CURSOR_ROWS = -1)
    BEGIN
    FETCH NEXT FROM TestCursor
    IF (@HiredModified = '04/07/2003')/*05/18/2006*/
    -- Sets @HiredModifiedDate data to use for the change
    SELECT @ChangeDateTo = '01/01/1901'
    UPDATE HumanResources.Employee
    SET [DateToChange] = @ChangeDateTo --'01/01/1901'
    FROM HumanResources.Employee
    WHERE CURRENT OF TestCursor;
    END
    -- CLOSE CURSOR
    CLOSE TestCursor;
    -- Remove any references held by cursor
    DEALLOCATE TestCursor;
    GO
    This query is run successfully but it does not produce the desired results to change the dates
    04/07/2003 to 01/01/1901.
    I would like the query to essentially be able to run the initial select statement, and then update and iterate through the returned results while replacing the necessary column in each row.
    I am also open to changes or a different design all together. 
    For this query I need:
    1. To narrow the initial set of information
    2. Check if the information returned, in particular a date, is before [i.e. this current month minus 12 months or
    12 months before current month]
    3. Next replace the dates with the needed date
    [Haven't written this out yet but it will need to be done]
    4. After all this is done I will then need to update a column on each row:
    if the 'date' is within 12 months to 12 months from the date checked
    NOTE: I am new to TSQL and have only been doing this for a few days, but I will understand or read up on what is explained if given enough information. Thank you in advance for anyone who may be able to help.

    The first thing you need to do is forget about cursors.  Those are rarely needed.  Instead you need to learn the basics of the tsql language and how to work with data in sets.  For starters, your looping logic is incorrect.  You open
    the cursur and immediately fetch the first row.  You enter the loop and the first thing in the loop does what?  Fetches another row.  That means you have "lost" the values from the first row fetched.  You also do not test the success of
    that fetch but immediately try to use the fetched value.  In addition, your cursor includes the condition "DateToChange = '01/01/1901' " - by extension you only select rows where HireDate is Jan 1 1901.  So the value fetched into @HiredModified will
    never be anything different - it will always be Jan 1 1901.  The IF logic inside your loop will always evaluate to FALSE.  
    But forget all that.  In words, tell us what you are trying to do.  It seems that you intend to add a new column to a table - one that is not null (ultimately) and is set to a particular value based on some criteria.  Since you intend the
    column to be not null, it is simpler to just add the column as not null with a default.  Because you are adding the column, the assumption is that you need to set the appropriate value for EVERY row in the table so the actual default value can be anything.
     Given the bogosity of the 1/1/1901 value, why not use this as your default and then set the column based on the Hiredate afterwards.  Simply follow the alter table statement with an update statement.  I don't really understand what your logic
    or goal is, but perhaps that will come with a better description.  In short: 
    alter table xxx add DateToChange date default '19010101'
    update xxx set DateToChange = HireDate where [some unclear condition]
    Lastly, you should consider wrapping everything you do in a transaction so that you recover from any errors.  In a production system, you should consider making a backup immediately before you do anything - strongly consider and have a good reason not
    to do so if that is your choice (and have a recovery plan just in case). 

  • How to count updated rows after an UPDATE?

    Is there a way to count updated rows after an update?
    Let's say I have an update like
    UPDATE table_a
    set field_1 = 'new_field'
    WHERE field_2 ='some_value' ;
    And now I would like to insert an info record into logging table like
    INSERT INTO logging_tbl (step, description, changed_rows) VALUES('UPDATE', 'update of table_a', ?);
    update is in sqlplus script.
    Thanks.
    Message was edited by:
    br00klynZ00

    Use SQL%ROWCOUNT.
    DECLARE
      v_num NUMBER := 0;
    BEGIN
    UPDATE table_a
    set field_1 = 'new_field'
    WHERE field_2 ='some_value' ;
    v_num := SQL%ROWCOUNT;
    INSERT INTO logging_tbl (step, description, changed_rows)
    VALUES('UPDATE', 'update of table_a', v_num);
    END;

  • Global succession updates are limited to 500 relationships. If more than 500 exist PLM presents a warning message and does not execute the update

    Global succession updates are limited to 500 relationships. If more than 500 exist PLM presents a warning message and does not execute the update.
    How/Where to increase the relationship count?
    The message which I can see :
    Warning:
    This specification has exceeded the number of parent relationships allowed by Where Used. The Where Used tool only supports up to 500 parent relationships.
    Thanks

    This really brings up a larger topic around change management.
    The questions you should start with is
    1. What kind of change is happening to the raw material? 
    2. Will this change affect anything upstream inside or outside of PLM4P? (Will this change affect nutrition, compliance, the ingredient statement, the label etc?)
    3. Who needs to approve this change?
    If they are non-material changes (changes that don't affect theoretical calculations, the ingredient statement, labeling, upstream systems that need to be notified etc) then you should be using get latest revision instead of global succession.   Get Latest Revision will automatically switch out the material with the latest approved version.  This logic is also configurable in case you need to add additional guard conditions.   We can also provide guidance around locking the get latest revision lock once a specification has reached the retired/obsolete state so changes won't occur for specifications in those statuses.
    If the changes to the raw material are material changes (changes that affect calculations, labeling etc) then the change should be reflected with a copy of the specification.  Dependent specifications then need to be re-issued so calculations can be performed and the appropriate workflow reviews can occur.   Smart Issue allows for filtering based on status and should let you re-issue in smaller blocks. 
    Let me know more about your change management strategy, how often large material changes happen and maybe example causes for those mass changes.  We can also schedule a change management training session for everyone where we can share our vision and tools available for change management.  This topic is quite large and generally requires a lot of business process discussion beyond just the tools available. 
    Thanks
    Kelly

  • Cannot successfully update any vaults

    I just upgraded to Aperture 3 and since then have not been able to successfully update any of my vaults. The library became too large for the external drive that housed my A Vault so I added a new vault on a separate drive that has ample room. When I clicked the update vault icon, aperture said it was calculating disk space and then said it was updating vault. When the update vault scrollbar reached about halfway it stopped moving. I left it run overnight and no change. I was able to then just click on any image and the update bar disappeared as if nothing ever happened. I checked the external drive to see if anything was there and a vault existed, but is much smaller in size than my actual library.
    I then went and picked up my offsite drive and brought it back to the office to back up. It did the same thing as above.
    I'm confused. I tried to go through the steps to repair my library, but each time I command, option click on the library it just opens Aperture instead of the repair dialogue. Is there another way to repair the library and does anyone have any other suggestions?
    Thanks!

    I too am experiencing vault issues, although not exactly the same as what you describe. My issues were posted to this discussion thread (see http://discussions.apple.com/thread.jspa?threadID=2631926&tstart=250) on Oct 30, and no one has provided their ideas or solutions in reply. The point I wish to make is that colleagues who regularly follow and post suggestions and answer questions seem to ignore issues with vaults. After I posted my question I searched all posts in this this thread where the word "vault" is used in the subject, and most if not all have zero responses and I can only conclude by the general absence of responses to vault issues that this feature of Aperture is not well known. In the last 90 days I encountered some 20 users with vault issues.
    If there are people out there who know how to update, reconnect, migrate, etc vaults - particularly when going from AP2 --> AP3, there are a number of us users who sure would appreciate their insights.
    Perhaps there are some Apple personnel on the Aperture Software Team who monitor this thread....if you are out there, then please chime in.

  • Update row.column1 with value from other_row.column1

    I have a problem with a bug recently discovered in one of our systems.
    It generates two rows with the same public_order_id (and also same customer_id, order_state, sub_customer_id, order_date and amount_paid).
    The "error row" which should be removed is one with:
    amount_paid <> 0 AND (amount_paid_main = 0 AND amount_paid_bonus = 0)
    The correct row is:
    amount_paid <> 0 AND NOT (amount_paid_main = 0 AND amount_paid_bonus = 0)
    However it is not as easy to just delete the error once. The customer_class is wrong in the correct row, it is stored in the error row. So I need to update the correct row with the customer_class from the error row. And I have no idea how to do this. I guess I need a PL/SQL to solve this. This error has occurred on 20 000 transactions so I cannot update it manually.
    How do I correct this with PL/SQL, or just with SQL? the internal_transaction_id is unique, but it is not certain that the error row is has a higher number than the correct row.
    I hope you understand what I want to do.
    This is example of the data(seperated by ;):
    CUSTOMER_ID;PUBLIC_ORDER_ID;ORDER_STATE;SUB_CUSTOMER_ID;ORDER_DATE;AMOUNT_PAID;CUSOMER_CLASS;INTERNAL_ORDER_ID;AMOUNT_PAID_MAIN;AMOUNT_PAID_BONUS;type of row
    SONY_ERICSON;1;FINISHED;45;2009-04-27;200;28;10;200;0;*<- correct row*
    SONY_ERICSON;1;FINISHED;45;2009-04-27;200;16;11;0;0;<- error row
    NOKIA;2;FINISHED;78;2009-04-16;200;32;12;200;0;*<- correct row*
    NOKIA;2;FINISHED;78;2009-04-16;200;5;13;0;0;<- error row
    MOTOROLA;3;FINISHED;65;2009-04-20;200;4;14;0;0;<- error row
    MOTOROLA;3;FINISHED;65;2009-04-20;200;105;15;200;50;*<- correct row*

    Hello, an update should suffice here:
    WITH test_table AS (
    SELECT 'SONY_ERICSON' CUSTOMER_ID,1 PUBLIC_ORDER_ID,'FINISHED' ORDER_STATE, 45 SUB_CUSTOMER_ID, TO_DATE('2009-04-27','YYYY-MM-DD') ORDER_DATE, 200 AMOUNT_PAID, 28 CUSTOMER_CLASS,10 INTERNAL_ORDER_ID,200 AMOUNT_PAID_MAIN, 0 AMOUNT_PAID_BONUS FROM DUAL UNION ALL
    SELECT 'SONY_ERICSON',1,'FINISHED',45, TO_DATE('2009-04-27','YYYY-MM-DD'), 200,16,11,0,0  FROM DUAL UNION ALL
    SELECT 'NOKIA',2,'FINISHED',78, TO_DATE('2009-04-16','YYYY-MM-DD'), 200,32,12,200,0 FROM DUAL UNION ALL
    SELECT 'NOKIA',2,'FINISHED',78, TO_DATE('2009-04-16','YYYY-MM-DD'), 200,5,13,0,0 FROM DUAL UNION ALL
    SELECT 'MOTOROLA',3,'FINISHED',65, TO_DATE('2009-04-20','YYYY-MM-DD'), 200,4,14,0,0 FROM DUAL UNION ALL
    SELECT 'MOTOROLA',3,'FINISHED',65, TO_DATE('2009-04-20','YYYY-MM-DD'), 200,105,15,200,50 FROM DUAL)
    -- end test data
    SELECT *
      FROM test_table
    WHERE NVL(amount_paid_main,0) + NVL(amount_paid_bonus,0) = 0;Confirming that we have the error records:
    CUSTOMER_ID  PUBLIC_ORDER_ID ORDER_ST SUB_CUSTOMER_ID ORDER_DAT AMOUNT_PAID CUSTOMER_CLASS INTERNAL_ORDER_ID AMOUNT_PAID_MAIN AMOUNT_PAID_BONUS
    SONY_ERICSON               1 FINISHED              45 27-APR-09         200             16                11                0                 0
    NOKIA                      2 FINISHED              78 16-APR-09         200              5                13                0                 0
    MOTOROLA                   3 FINISHED              65 20-APR-09         200              4                14                0                 0Then, something like:
    UPDATE test_table tt1
        SET tt1.CUSTOMER_CLASS =
      (SELECT tt2.CUSTOMER_CLASS
          FROM test_table
         WHERE  NVL(amount_paid_main,0) + NVL(amount_paid_bonus,0) = 0
              AND tt1.CUSTOMER_ID = tt2.CUSTOMER_ID
              AND tt1.PUBLIC_ORDER_ID = tt2.PUBLIC_ORDER_ID)
    WHERE NVL(tt1.amount_paid_main,0) + NVL(tt1.amount_paid_bonus,0) > 0;

  • Update Row into Run Table Task is not executing in correct sequence in DAC

    Update Row into Run Table Task is not executing in correct sequence in DAC.
    The task phase for this task is "Post Lost" . The depth in the execution plan is 19 but this task is running some times in Depth 12, some times in 14 and some time in Depth 16. Would like to know is this sequence of execution is correct order or not? In the out of the Box this task is executed at the end of the entire load. No Errors were reported in DAC log.
    Please let me know if any documents that would highlight this issue
    rm

    Update into Run table is a task thats required to update a table called W_ETL_RUN_S. The whole intention of this table is to keep the poor mans run history on the warehouse itself. The actual run history is stored in the DAC runtime tables, however the DAC repository could be on some other database/schema other than warehouse. Its mostly a legacy table, thats being carried around. If one were to pay close attention to this task, it has phase dependencies defined that dictate when this task should run.
    Apologies in advance for a lengthy post.... But sure might help understanding how DAC behaves! And is going to be essential for you to find issues at hand.
    The dependency generation in DAC follows the following rules of thumb!
    - Considers the Source table target table definitions of the tasks. With this information the tasks that write to a table take precedence over the tasks that reads from a table.
    - Considers the phase information. With this information, it will be able to resolve some of the conflicts. Should multiple tasks write to the same table, the phase is used to appropriately stagger them.
    - Considers the truncate table option. Should there be multiple tasks that write to the same table with the same phase information, the task that truncates the table takes precedence.
    - When more than one task that needs to write to the table that have similar properties, DAC would stagger them. However if one feels that either they can all go in parallel, or a common truncate is desired prior to any of the tasks execution, one could use a task group.
    - Task group is also handy when you suspect the application logic dictates cyclical reads and writes. For example, Task 1 reads from A and writes to B. Task 2 reads from B and writes back to A. If these two tasks were to have different phases, DAC would be able to figure that out and order them accordingly. If not, for example those tasks need to be of the same phase for some reason, one could create a task group as well.
    Now that I described the behavior of how the dependency generation works, there may be some tasks that have no relevance to other tasks either as source tables or target tables. The update into run history is a classic example. The purpose of this task is to update the run information in the W_ETL_RUN_S with status 'Completed' with an end time stamp. Because this needs to run at the end, it has phase dependency defined on it. With this information DAC will be able to stagger the position of execution either before (Block) or after (Wait) all the tasks belonging to a particular phase is completed.
    Now a description about depth. While Depth gives an indication to the order of execution, its only an indication of how the tasks may be executed. Its a reflection of how the dependencies have been discovered. Let me explain with an example. The tasks that have no dependency will have a depth of 0. The tasks that depend on one or more or all of depth 0 get a depth of 1. The tasks that depend on one or more or all of depth 1 get a depth of 2. It also means implicitly a task of depth 2 will indirectly depend on a task of depth 0 through other tasks in depth 1. In essence the dependencies translate to an execution graph, and is different from the batch structures one usually thinks of when it comes to ETL execution.
    Because DAC does runtime optimization in the order in which tasks are executed, it may pick a task thats of order 1 over something else with an order of 0. The factors considered for picking the next best task to run depend on
    - The number of dependent tasks. For example, a task which has 10 dependents gets more priorty than the one whose dependents is 1.
    - If all else equal, it considers the number of source tables. For example a task having 10 source tables gets more priority than the one that has only two source tables.
    - If all else equal, it considers the average time taken by each of the tasks. The longer running ones will get more preference than the quick running ones
    - and many other factors!
    And of course the dependencies are honored through the execution. Unless all the predecessors of a task are in completed state a task does not get picked for execution.
    Another way to think of this depth concept : If one were to execute one task at a time, probably this is the order in which the tasks will be executed.
    The depth can change depending on the number of tasks identified for the execution plan.
    The immediate predecessors and successor can be a very valuable information to look at and should be used to validate the design. All predecessors and successors provide information to corroborate it even further. This can be accessed through clicking on any task and choosing the detail button. You will see all these information over there. As an alternate method, you could also use the 'All/immediate Predecessors' and 'All/immediate Successor' tabs that provide a flat view of the dependencies. Note that these tabs may have to retrieve a large amount of data, and hence will open in a query mode.
    SUMMARY: Irrespective of the depth, validate
    - if this task has 'Phase dependencies' that span all the ETL phases and has a 'Wait' option.
    - click on the particular task and verify if the task does not have any successors. And the predecessors include all the tasks from all the phases its supposed to wait for!
    Once you have inspected the above two you should be good to go, no matter what the depth says!
    Hope this helps!

  • Doubt Regarding Updated Rows

    Hello,
    After using Bulk Collect & FORALL for updating rows in a table
    How to find the total number of rows Affected (Updated) ...
    please explain by an example..??

    Hi Aijaz,
    If i'm correct you need to know the number of rows updated after the DML.
    This might help.
    -- Example Using the RETURNING Clause with a Record
    DECLARE
    TYPE setRec IS RECORD (key_name settings.settings_key%TYPE,
    value_1 settings.settings_date_value%TYPE );
    TYPE t_set_info IS TABLE OF setRec;
    set_info t_set_info := t_set_info( NULL );
    BEGIN
    UPDATE settings SET settings_date_value = SYSDATE WHERE settings_key LIKE '%DATE%'
    RETURNING settings_key, settings_date_value BULK COLLECT INTO set_info;
    DBMS_OUTPUT.PUT_LINE('Total rows ' || set_info.COUNT );
    ROLLBACK;
    END;
    /

  • Array Bind: nbr of updated rows?

    Hello,
    when using array binding with UPDATE statements, how to look up the number of updated rows?
    I couldn't find any parameter property such as ArrayBindAffectedRows.
    Is it possible to use array bind with SQL statements which return values, e.g.:
    UPDATE emp SET salary = salary + :increase
    WHERE mgr = :mgrNo
    RETURNING salary INTO :newSalary;
    Hm, arrays :increase and :newSalary might have different lengths.
    Thanks,
    Armin

    Ok this is genuinly tricky.
    The only way I can think of to get this is to use FORALL and BULK COLLECT. This does an array-bound insert from PL/SQL. But you need to pass Associative Arrays from ODP.NET to PL/SQL to get this started.
    Any other solution I could think of would require running some PL/SQL code for each update statement, for instance in a trigger. But avoiding the context switches from PL/SQL to SQL is a main reason to use array binding in the first place.
    Here's a complete sample program:
    I used inline PL/SQL for compactness, but you might want to save the block as a procedure.
    using System;
    using System.Data;
    using Oracle.DataAccess.Client;
    using Oracle.DataAccess.Types;
         public class Test
          static OracleConnection connect()
            string constr = "data source=oracle;user id=scott;password=tiger";
            OracleConnection con = new OracleConnection(constr);
            con.Open();
            return con;
        const string sql = @"
    declare
      type NumTable is table of Number index by binary_integer;
      l_managers NumTable := :mgr;
      l_increase NumTable := :inc;
      l_newSals NumTable;
      l_records int;
    begin
      forall idx in l_managers.first .. l_managers.last
        update emp
        SET
        sal = sal + l_increase(idx)
        WHERE mgr = l_managers(idx)
        RETURNING sal BULK COLLECT INTO l_newSals;
      :records_affected := l_newSals.count;
    end;
        [STAThread]
        static void Main(string[] args)
          try
            using (OracleConnection con = connect())
              string cr = new String(new char[] {(char)13});
              OracleCommand cmd = new OracleCommand(sql.Replace(cr,""),con);
              OracleDecimal[] increases = new OracleDecimal[] {10,20,30};
              int[] managers = new int[] { 7698,7839,7782};
             OracleParameter pMgr = cmd.Parameters.Add("manager",
                 OracleDbType.Int32,
                 ParameterDirection.Input);
              pMgr.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
              pMgr.Size = managers.Length;
              pMgr.Value = managers;
              OracleParameter pInc = cmd.Parameters.Add("increase",
                 OracleDbType.Decimal,
                 ParameterDirection.Input);
              pInc.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
              pInc.Size = increases.Length;
              pInc.Value = increases;
              OracleParameter pRecs = cmd.Parameters.Add("records",
                 OracleDbType.Int32 ,
                 ParameterDirection.Output);
              pRecs.CollectionType = OracleCollectionType.None;
              cmd.ExecuteNonQuery();
              int recs = (int)pRecs.Value;
              Console.WriteLine("{0} records affected",recs );
          catch (Exception ex)
            Console.WriteLine(ex);
    }

  • How can find SCN or sequence number on the update operation?

    nedd to recovery database, how can find the SCN or sequence number before the update exection?
    thanks

    nedd to recovery database, how can find the SCN or
    sequence number before the update exection?Sorry - there is something confusing about your question ...
    It seems to me the SCN is the 'system change number', which identifies when a change (table, row, block, flush log buffer to log file, etc) has ocurred.
    You seem to be asking for the SCN associated with an update before the update actually occurred.
    Are you actually asking "How do I perform a point in time recovery to immediately before a specific update?"
    Perhaps you could include a few more details, such as database version. For some reason different versions have different capabilities - that could be helpful here.

  • Update Row return blank page

    Hello there,
    I created a master detail form with a tabular form that will update two columns (Comments and Status)  when I click a button to applied changes. The master region is a dynamic list of value that receive a character value (eg Error Code) and this dynamicly will trigger the detail to populate the tabular form depending on the number of Error code rows in the database. When I pass the Error Code value and this Error Code  has less then 50 rows on the tabular form and when I click the button to perform the update,  the two columns will update without problem. When the Error Code has over
    50 rows on the tabular form this will execute and will show a blank page. Is anyone have notice this type of problem and did you solve it?
    Your insight is much appreciated.
    Ghislain

    Hi all,
    I've found the reason of getting a blank page. I was creating a Section for each course, hence there are a total of 220 sections in the page I was trying to retrieve. When I reduce that to 217 section, the page work fine.
    However I would like to know if '217' is the maximum number of section for a page?
    Cheers,
    Jia Huey

  • There was an error while updating row count for "SH".."SH".CHANNELS

    Hi All,
    Am new to OBIEE.Pls help in this regard.
    Am building the physical layer as per Repository guide.When am importing the data in to this,am getting the below error.
    *"There was an error while updating row count for "SH".."SH".CHANNELS" :"*
    channles is the table name and having 5 rows.
    but am able to see the data in the sql prompt. like SELECT * FROM SH.CHANNELS then 5 rows data would be displaying..
    pls help in this regard and where is the excat problem?
    Thanks,

    what is the error?
    Make sure that your connection pool settings are okay..
    Make sure that, you are using correct driver in case of if you are using ODBC dsn..
    Also make sure that, your oracle server is running... TNS and Oracle server services

  • Number of currently displayed rows in report with pagination?

    Maybe I'm thinking to complicated, but ...
    In my report I use the HTMLDB_ITEM.CHECKBOX function in order to display a checkbox for each row:
    HTMLDB_ITEM.CHECKBOX(1,"ID",NULL,:P311_ASSIGNED,':') " "
    Some of the checkboxes are selected depending on whether there is an entry for them in a database table.
    As the report returns hundreds of rows, I use pagination (e.g. 15 rows per page).
    After checking/unchecking the checkboxes and submitting the page by clicking the save button, I want to do the following: For each row CURRENTLY DISPLAYED on the screen (1) check, whether its checkbox is currently checked or not (2a) If it is checked and there is not yet an entry -> add row to the db table (2b) If it is unchecked and there is an entry in the db table -> remove row from db table.
    How can I, on the server side, find out which rows (row ids) are currently displayed (using pagination), so that I check each of the currently displayed row ids for their existence in the database table? Is there any item stored on the server side, which tells me the row number of the first row currently displayed? Is there an item I can refer to, which tells me the amount of rows, which are displayed on one page?
    Your help would be very much appreciated!
    Konrad

    Hi Konrad,
    I will jump in. :-) Just have a few minutes before a meeting.
    I think you don't have to make it that complicated, where you have to know the current pagination.
    1) Your HTMLDB_ITEM.CHECKBOX has to contain as checked value #ROWNUM# as the row selector would do it.
    2) You have to create a hidden item where you store your customer id
    3) create another hidden item where you store if the customer has already the assignment
    4) In your process you are now able to loop through your arrays.
    DECLARE
        vRowNumber BINARY_INTEGER;
        vFound BOOLEAN;
    BEGIN
        -- insert new event assignments
        FOR ii IN 1 .. WWV_Flow.g_f01.COUNT -- your checkbox
        LOOP
            vRowNumber := WWV_Flow.g_f01(ii);
            -- no assignment yet?
            IF WWV_Flow.g_f03(vRowNumber) IS NULL -- your hidden field where you store if you have an assmnt
            THEN
                INSERT INTO xxx VALUES (WWV_Flow.g_f02(vRowNumber)); -- your customer id
            END IF;
        END LOOP;
        -- delete old event assignments
        FOR ii IN 1 .. WWV_Flow.g_f03.COUNT -- your hidden field where you store if you have an assmnt
        LOOP
            -- only if the event was already assigned
            IF WWV_Flow.g_f03(ii) IS NOT NULL
            THEN
                vFound := FALSE;
                FOR jj IN 1 .. WWV_Flow.g_f01.COUNT -- your checkbox
                LOOP
                    -- is the event still checked?
                    IF WWV_Flow.g_f01(jj) = ii
                    THEN
                        vFound := TRUE;
                        EXIT;
                    END IF;
                END LOOP;
                IF NOT vFound
                THEN
                    DELETE xxx WHERE CUSTOMER_ID = WWV_Flow.g_f02(ii);
                END IF;
            END IF;
        END LOOP;
    END LOOP;Haven't tested the code, but I think it should show the idea.
    Hope that helps
    Patrick
    Check out my APEX-blog: http://inside-apex.blogspot.com

  • How can i update rows  in a table based on a match from a select query

    Hello
    How can i update rows in a table based on a match from a select query fron two other tables with a update using sqlplus ?
    Thanks Glenn
    table1
    attribute1 varchar2 (10)
    attribute2 varchar2 (10)
    processed varchar2 (10)
    table2
    attribute1 varchar2 (10)
    table3
    attribute2 varchar2 (10)
    An example:
    set table1.processed = "Y"
    where (table1.attribute1 = table2.attribute1)
    and (table1.attribute2 = table3.attribute2)

    Hi,
    Etbin wrote:
    Hi, Frank
    taking nulls into account, what if some attributes are null ;) then the query should look like
    NOT TESTED !
    update table1 t1
    set processed = 'Y'
    where exists(select null
    from table2
    where lnnvl(attribute1 != t1.attribute1)
    and exists(select null
    from table3
    where lnnvl(attribute2 != t1.attribute2)
    and processed != 'Y'Regards
    EtbinYes, you could do that. OP specifically requested something else:
    wgdoig wrote:
    set table1.processed = "Y"
    where (table1.attribute1 = table2.attribute1)
    and (table1.attribute2 = table3.attribute2)This WHERE clause won't be TRUE if any of the 4 attribute columns are NULL. It's debatable about what should be done when those columns are NULL.
    But there is no argument about what needs to be done when processed is NULL.
    OP didn't specifically say that the UPDATEshould or shouldn't be done on rows where processed was already 'Y'. You (quite rightly) introduced a condition that would prevent redo from being generated and triggers from firing unnecessarily; I'm just saying that we have to be careful that the same condition doesn't keep the row from being UPDATEd when it is necessary.

Maybe you are looking for

  • My iPhone 5 bricked when upgrading to iOS 7. Now it is stuck at the activation part and will not activate.

    I downloaded the iOS 7 but it would not install so i tethered it to my computer the connect to iTunes screen came on the iPhone. But after a few minutes, it crashed and iTunes told me it was in recovery mode and that it will be restored to factory se

  • Is there a size limit for hard drive boot partition?

    I have been using Drive Genius to adjust the size of my boot partition larger. But it doesn't seem to allow for much increase, even though I deleted the second partition and tried to apply the disk space to DH1: (boot - there is a single partition on

  • Installing iWork on Mac OS X Server

    I've installed my copy of iWork '06 on Mac OS X Server because I need to be able to read some Pages files on the development box. It installed fine (no errors) but when I try to launch Pages I get weird behaviour from the App. It's screens won't rend

  • Need laser suggestions for my Mac

    I'm looking for suggestions on network laser printers (preferably color) for our Macs. I mange a network with mostly PCs and some Macs. We have a number of Lexmark and HP printers on the network. The HP printers tend to be fussy with our Mac users, w

  • Access to object that call me?

    Any can help me with this problem. I got: ClassA ClassB ClassC They all mine. and derived from Object. I create "objectA" of ClassA, then call method of "objectA", which call method of "objectB" (ClassB) which call method of "objectC".. At end of thi