开发者

Update records details using Oracle 10g DB and VB.net

I am trying to figure out how to get some output as to what records were updated when running this query:

UPDATE   CSR.TARGET ces 
SET      (STATUS_CODE, COMPLETE_DATE, DATA) = 
     (SELECT    'ERROR', '', REPLACE(c.Data, ' x</csr', '</csr') 
     FROM       CSR.TARGET C 
     WHERE      (c.EID = ces.EID) 
     AND        c.STATUS_CODE = 'ERROR') 
WHERE    EXISTS (SELECT 1 
FROM     CSR.TARGET C 
WHERE    (c.EID = ces.EID) 
AND      c.STATUS_CODE = 'ERROR')

If there are 3 records that were updated by that above query then i would like to know what they were (record ID, etc). How would i go about doing that?

Currently it just tells me 3 records were updated and thats it. No other details.

Any help would be great! Thanks :o)

UPDATE

I am needing this for a query using VB.net so i do not think i can do PL/SQL type of thing?

    Dim OracleCommand As New OracleCommand()
    Dim ra As Integer

    OracleCommand = New OracleCommand("UPDATE   CSR.TARGET ces " & _
                                      "SET      (STATUS_CODE, COMPLETE_DATE, DATA) = " & _
                                                "(SELECT    'ERROR', '', REPLACE(c.Data, ' x</c开发者_运维技巧sr', '</csr') " & _
                                                "FROM       CSR.TARGET C " & _
                                                "WHERE      (c.EID = ces.EID) " & _
                                                "AND        c.STATUS_CODE = 'ERROR') " & _
                                      "WHERE    EXISTS (SELECT 1 " & _
                                      "FROM     CSR.TARGET C " & _
                                      "WHERE    (c.EID = ces.EID) " & _
                                      "AND      c.STATUS_CODE = 'ERROR')", OracleConnection)

    Try
        ra = OracleCommand.ExecuteNonQuery()
        OracleConnection.Close()
 ....

David


You should be able to use the RETURNING clause. Assuming that the EID column is the "record ID" you're referring to and that it is numeric

CREATE OR REPLACE TYPE num_tbl
IS 
TABLE OF NUMBER;

DECLARE
  l_modified_eids num_tbl;
BEGIN
  UPDATE csr.target ces
     SET <<omitted>>
   WHERE <<omitted>>
   RETURNING eid
     BULK COLLECT INTO l_modified_eids;

  <<Iterate through l_modified_eids to see which rows are modified>>
END;


Based on my reading of that query, all records that have an EID that matches the EID of a record who's status_code is 'ERROR' will be udpated. So if you have a table like this:

ID   EID  STATUS_CODE
--   ---  -----------
 1     1    ERROR
 2     1    OKAY
 3     2    OKAY

both records with ID 1 and 2 would be updated, because 2's EID field matches 1's EID field, and 1's EID field shows error. When it updates, it always uses the data from the row with the 'ERROR'.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜