更新查询在 SQL Server 中运行,但不在 Oracle 中运行
我需要此更新查询在 SQL Server 和 Oracle 上运行。如果重要的话,我们的 Oracle 版本是 10.2。当我在 Oracle 中运行查询时,出现“ERROR ORA-00933:SQL 命令未正确结束”。我需要做什么才能让它在 Oracle 中运行?
UPDATE dbo.tableUpdate
SET fieldA = tt.fieldB
FROM dbo.tableTranslate tt
WHERE
tt.fieldC = dbo.tableUpdate.fieldC
AND
tt.fieldD = dbo.tableUpdate.fieldA
AND
1 = (
SELECT COUNT(tblTrans.fieldD)
FROM dbo.tableTranslate tblTrans
WHERE
tblTrans.fieldC = dbo.tableUpdate.fieldC
AND
tblTrans.fieldD = dbo.tableUpdate.fieldA
)
I need this update query to run on both SQL Server and Oracle. Our Oracle version is 10.2 if that matters. When I run the query in Oracle I get "ERROR ORA-00933: SQL command not properly ended". What do I need to do to get this to run in Oracle?
UPDATE dbo.tableUpdate
SET fieldA = tt.fieldB
FROM dbo.tableTranslate tt
WHERE
tt.fieldC = dbo.tableUpdate.fieldC
AND
tt.fieldD = dbo.tableUpdate.fieldA
AND
1 = (
SELECT COUNT(tblTrans.fieldD)
FROM dbo.tableTranslate tblTrans
WHERE
tblTrans.fieldC = dbo.tableUpdate.fieldC
AND
tblTrans.fieldD = dbo.tableUpdate.fieldA
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
UPDATE...FROM 语法对 Oracle 无效。您将需要使用子查询,如下所示:
The UPDATE...FROM syntax is not valid for Oracle. You will need to use a subquery, like this:
Oracle 中相关子查询的语法略有不同。
The syntax for co-related sub query is a little different in Oracle.
您将需要完全重写 Oracle 查询。有些东西在 Oracle 10.2 中不起作用:
update
句子中的from
子句(您需要为此编写一个子选择)dbo
架构,除非您在 Oracle 中实际上有一个名为 dbo 的用户拥有您要更新的表You will need to rewrite completely your query for Oracle. Some stuff that won't work in Oracle 10.2:
from
clause inupdate
sentence (you will need to write a subselect for this)dbo
schema, unless you actually have a user nameddbo
in oracle owning the table you are trying to update