使用 Oracle 10g DB 和 VB.net 更新记录详细信息
我试图弄清楚如何获取有关运行此查询时更新了哪些记录的输出:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该能够使用 RETURNING 子句。假设
EID
列是您引用的“记录 ID”并且它是数字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根据我对该查询的阅读,所有 EID 与 status_code 为“ERROR”的记录的 EID 相匹配的记录都将被更新。因此,如果您有一个像这样的表:
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:
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'.