使用 Oracle 中的 Join 查询进行更新
查询有什么问题? (它无限期地执行)
UPDATE table1 t1 SET (t1.col,t1.Output) = (
SELECT t2.col, t3.Output + t2.col
FROM tabl2 t3
LEFT JOIN table1 t2 ON t3.Join_Key = t2.Join_Key
WHERE t2.col is not NULL);
请帮助我。
what is wrong in query? (it executes indefinitely)
UPDATE table1 t1 SET (t1.col,t1.Output) = (
SELECT t2.col, t3.Output + t2.col
FROM tabl2 t3
LEFT JOIN table1 t2 ON t3.Join_Key = t2.Join_Key
WHERE t2.col is not NULL);
Please, help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除非您的
SELECT
子查询返回单行,否则您的UPDATE
语句应该失败并出现错误:一般来说,如果您有相关更新,则需要一些条件来关联外部中的行table
T1
到内部子查询中的行,以确保子查询返回单行。这通常看起来像最后,这个
UPDATE
语句正在更新T1
中的每一行。这就是你的意图吗?或者您只想更新在子查询中找到匹配项的行?Unless your
SELECT
subquery returns a single row, yourUPDATE
statement should fail with the errorGenerally, whey you have a correlated update, you need some condition that relates rows in the outer table
T1
to rows in the inner subquery in order to ensure that the subquery returns a single row. That would generally look something likeFinally, this
UPDATE
statement is updating every row inT1
. Is that what you intend? Or do you only want to update the rows where, for example, you find a match in your subquery?您的查询对于通用 table1、table2 和 join_key 引用没有多大意义。
如果这不是您正在寻找的结果,那么拥有一些示例数据将有助于更好地了解您正在寻找的结果。
Your query does not make a whole lot of sense with the generic table1, table2, and join_key references.
If this is not what you are looking for, it would be helpful to have some sample data to get a better idea of what results you are looking for.