在 Derby 中一次更新多个列
DB2 支持这种语法:
UPDATE DEST D SET (AAA,BBB) = (
SELECT MAX(Z.AAA), MAX(Z.BBB) FROM OTHER O WHERE O.ID = D.ID
)
即我可以运行一个返回多列的选择,并将结果复制到目标表的各个列(要更新的列)。
Derby 仅允许语法:
UPDATE table-Name [[AS] correlation-Name]
SET column-Name = Value
[ , column-Name = Value} ]*
[WHERE clause]
这意味着当我需要以某种方式对选择的结果进行分组时,我可能会遇到问题。 有没有比将更新拆分为两个语句或在 Java 循环中本地执行此操作(即提交数百万个 UPDATE 语句)更好的解决方案?
DB2 supports this syntax:
UPDATE DEST D SET (AAA,BBB) = (
SELECT MAX(Z.AAA), MAX(Z.BBB) FROM OTHER O WHERE O.ID = D.ID
)
i.e. I can run a select which returns more than one column and copy the results into various columns of the destination table (the one to update).
Derby only allows the syntax:
UPDATE table-Name [[AS] correlation-Name]
SET column-Name = Value
[ , column-Name = Value} ]*
[WHERE clause]
which means I can run into problems when I need to group the results of the select in some way. Is there a better solution than splitting the update into two statements or doing this locally in a loop in Java (i.e. submitting millions of UPDATE statements)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
想必,您可以这样做:
我没有说任何关于高效的事情 - 但它可能比将更新分成两个语句或在本地循环中执行更有效。
Presumably, you can do this:
I didn't say anything about efficient - but it is likely more efficient than either splitting the update into two statements or doing it locally in a loop.