【发布时间】:2012-08-23 08:41:33
【问题描述】:
我有一张表格可以记录我库存中链轮的物理质量。
create table sprockets(
id NUMBER,
mass NUMBER
);
INSERT into sprockets VALUES (1, 4);
INSERT into sprockets VALUES (2, 8);
INSERT into sprockets VALUES (3, 15);
INSERT into sprockets VALUES (4, 16);
INSERT into sprockets VALUES (5, 23);
INSERT into sprockets VALUES (6, 42);
我聘请链轮机械师对我的链轮进行日常维护。如果他们的修改使链轮的质量发生了变化,他们会在维护报告中记录下来。
create table maintenance_events(
sprocket_id NUMBER,
new_mass NUMBER
);
--chipped a widget off of sprocket #1; mass reduced to 3 kg
INSERT into maintenance_events VALUES (1, 3);
--new lead bearings makes sprocket #2 weigh 413 kg
INSERT into maintenance_events VALUES (2, 413);
我想使用每个链轮的当前质量来更新sprockets 表。我想采用maintenance_events 中的new_mass 并覆盖sprockets 中的旧mass 值。我参考了this question 的前两个答案,但都给出了错误。
UPDATE sprockets
set mass = maintenance_events.new_mass
from sprockets, maintenance_events
where sprockets.id = maintenance_events.sprocket_id
Error at Command Line:2 Column:38
Error report:
SQL Error: ORA-00933: SQL command not properly ended
UPDATE sprockets
set sprockets.mass = maintenance_events.new_mass
from sprockets
INNER JOIN maintenance_events
on sprockets.id = maintenance_events.sprocket_id
Error at Command Line:2 Column:48
Error report:
SQL Error: ORA-00933: SQL command not properly ended
我做错了什么?
【问题讨论】:
-
除非您只为每个 sprocket 保留最新的维护事件,否则您可能还希望在该表中存储一个日期,以便您可以确定您使用的是该 sprocket 的最新值跨度>
-
所有语句都以分号结尾吗?我找到了this link
-
@Joe,这在我的 2.0 版本列表中。目前,我的维护数据集保证具有唯一的链轮 ID。
-
链接的 Q 是关于 SQL Server 的。 Oracle 不支持“UPDATE...FROM...”
标签: sql oracle11g sql-update