使用 Oracle 10g DB 和 VB.net 更新记录详细信息

发布于 2024-10-26 09:22:47 字数 1695 浏览 2 评论 0原文

我试图弄清楚如何获取有关运行此查询时更新了哪些记录的输出:

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')

如果上面的查询更新了 3 条记录,那么我想知道它们是什么(记录 ID 等)。我该怎么做呢?

目前它只告诉我更新了 3 条记录,仅此而已。没有其他细节。

任何帮助都会很棒!谢谢:o)

更新

我需要这个来使用 VB.net 进行查询,所以我不认为我可以做 PL/SQL 类型的事情?

    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</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')", OracleConnection)

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

大卫

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</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')", OracleConnection)

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

David

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

厌倦 2024-11-02 09:22:47

您应该能够使用 RETURNING 子句。假设 EID 列是您引用的“记录 ID”并且它是数字

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;

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;
梦里的微风 2024-11-02 09:22:47

根据我对该查询的阅读,所有 EID 与 status_code 为“ERROR”的记录的 EID 相匹配的记录都将被更新。因此,如果您有一个像这样的表:

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

ID 为 1 和 2 的两条记录都将被更新,因为 2 的 EID 字段与 1 的 EID 字段匹配,并且 1 的 EID 字段显示错误。更新时,它始终使用带有“ERROR”的行中的数据。

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'.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文