Why can#39;t I update more than one column at the same time using With keyword?(为什么我不能使用 With 关键字同时更新多个列?)
问题描述
我有一个如下所示的更新语句,它工作正常,我在子查询中使用了一个 with 语句来大大提高性能,但由于某种原因,我不允许从同一个表中添加一个额外的列来更新.
I have an update statement shown below that works fine, I used a with statement in the subquery to greatly improve performance but for some reason I'm not allowed to add an additional column from the same table to update.
作品:
UPDATE Table_A SET (Col_One) = (WITH OneValue AS (SELECT DISTINCT t.Col_One
FROM Table_Two t, Table_A a
WHERE t.id = a.New_Id))
SELECT Col_One FROM OneValue);
我想要做的只是包括另一个列,也像这样从 table_two 更新
What I'd like to do is just include another column to update also from table_two like this
UPDATE Table_A SET (Col_One, Col_Two) = (WITH OneValue AS (SELECT DISTINCT t.Col_One, T.Col_two
FROM Table_Two t, Table_A a
WHERE t.id = a.New_Id))
SELECT Col_One, Col_Two FROM OneValue);
但我得到 ora-01767 更新集表达式必须是子查询.我理解这个错误,但看不到我是如何生成它的.非常感谢任何帮助.
but I get ora-01767 update set expression must be a subquery. I understand this error but fail to see how I'm generating it. Any help is greatly appreciated.
提前致谢.
推荐答案
这似乎可行(无论如何,它通过使用 DUAL 进行简单查询):
This appears to work (it did with a simple query using DUAL anyway):
UPDATE Table_A SET (Col_One, Col_Two) = (select col_one, col_two from
(WITH OneValue AS (SELECT DISTINCT t.Col_One, T.Col_two
FROM Table_Two t, Table_A a
WHERE t.id = a.New_Id))
SELECT Col_One, Col_Two FROM OneValue)
);
至于子查询以WITH"开头为什么不起作用,我只能想象是因为Oracle SQL的设计者没有预料到这种用法.
As for why it doesn't work if the subquery starts with "WITH", I can only imagine that it is because the designers of Oracle SQL hadn't anticipated this usage.
这篇关于为什么我不能使用 With 关键字同时更新多个列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么我不能使用 With 关键字同时更新多个列?
基础教程推荐
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
