用 Oracle 中的两个表更新 SQL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4934673/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Update SQL with two tables in Oracle
提问by Soner G?nül
I have a sql like this
我有一个这样的 sql
UPDATE A
SET A.TEMSILCI_KOD = 4
FROM S_MUSTERI A, S_TEKLIF B
WHERE A.TEMSILCI_KOD = 9
AND B.BAYI_KOD = 17
AND A.HESAP_NO = B.HESAP_NO
But i getting an error like this
但我收到这样的错误
Error starting at line 8 in command:
UPDATE A
SET A.TEMSILCI_KOD = 4
FROM S_MUSTERI A, S_TEKLIF B
WHERE A.TEMSILCI_KOD = 9
AND B.BAYI_KOD = 17
AND A.HESAP_NO = B.HESAP_NO
Error at Command Line:9 Column:22
Error report:
SQL Error: ORA-00933: SQL command not properly ended
00933. 00000 - "SQL command not properly ended"
*Cause:
*Action:
Where is the ERROR
?
在哪里ERROR
?
回答by pascal
Maybe something like
也许像
UPDATE S_MUSTERI
SET TEMSILCI_KOD = 4
WHERE TEMSILCI_KOD = 9
AND EXISTS (SELECT 1 FROM S_TEKLIF B
WHERE S_MUSTERI.HESAP_NO = B.HESAP_NO
AND B.BAYI_KOD = 17)
回答by Vincent Malgrat
In Oracle the syntax to update a view is different from SQL*Server's syntax. In Oracle you could issue the following query:
在 Oracle 中,更新视图的语法与 SQL*Server 的语法不同。在 Oracle 中,您可以发出以下查询:
UPDATE (SELECT A.TEMSILCI_KOD
FROM S_MUSTERI A, S_TEKLIF B
WHERE A.TEMSILCI_KOD = 9
AND B.BAYI_KOD = 17
AND A.HESAP_NO = B.HESAP_NO)
SET TEMSILCI_KOD = 4
Note: This query will only work in Oracle if (S_TEKLIF.BAYI_KOD, S_TEKLIF.HESAP_NO)
is unique (so that the update will not be ambiguous and each row from S_MUSTERI
will be updated at most once).
注意:这个查询只有在唯一的情况下才能在 Oracle 中工作(S_TEKLIF.BAYI_KOD, S_TEKLIF.HESAP_NO)
(这样更新不会有歧义,并且每行S_MUSTERI
最多更新一次)。
回答by Doug Porter
Your update statement does not follow the correct syntax. There is no from clause in the update statement. It should follow the format
您的更新语句不遵循正确的语法。更新语句中没有 from 子句。它应该遵循格式
Update <table>
set <column> = <value>
where <conditions>
See this documentation on update: http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_10007.htm#i2067715
请参阅有关更新的此文档:http: //download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_10007.htm#i2067715