【发布时间】:2014-04-08 11:08:07
【问题描述】:
我的以下陈述有什么问题:
UPDATE TableToUpdate SET ColumnToUpdate = (
SELECT ColumnWithNewValues
FROM (
SELECT ColumnWithNewValues, ROWNUM AS N
FROM Table1 t1, Table2 t2 -- join tables
WHERE t2.Schluessel = t1.Schluessel -- join condition
AND t1.DateFrom <= TableToUpdate.Date -- <==== Error, reference to TableToUpdate
AND t1.DatumTo >= TableToUpdate.Date
-- ... some other conditions, not important here ...
) tmp
WHERE tmp.N = 5 -- Use the fifth row to update the row of TableToUpdate
)
执行此操作时,我会从 oracle 收到错误消息:
ORA-00904: "TableToUpdate"."Date": Ungültiger Bezeichner
在英语中我认为这意味着:
ORA-00904: "TableToUpdate"."Date": Invalid identifier
因此,我似乎无法从 SELECT 语句中的相关子查询中引用 TableToUpdate。在 MSSQL 下,这在将 oracle 特定的 ROWNUM 替换为 当然是等效的技术。
有人可以帮我吗?
【问题讨论】:
标签: sql oracle select sql-update correlated-subquery