使用 Oracle 中的两个表更新 SQL

发布于 2024-10-16 14:01:45 字数 594 浏览 4 评论 0原文

我有这样的 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

但我收到这样的错误

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:

ERROR 在哪里?

I have a sql like this

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

记忆で 2024-10-23 14:01:45

也许像

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)

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)
著墨染雨君画夕 2024-10-23 14:01:45

在 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

注意:此查询仅在 (S_TEKLIF.BAYI_KOD, S_TEKLIF.HESAP_NO) 唯一的情况下才在 Oracle 中工作(这样更新就不会含糊不清,并且来自的每一行) S_MUSTERI 最多更新一次)。

In Oracle the syntax to update a view is different from SQL*Server's syntax. In Oracle you could issue the following query:

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).

南汐寒笙箫 2024-10-23 14:01:45

您的更新语句不遵循正确的语法。 update 语句中没有 from 子句。它应该遵循以下格式

Update <table> 
   set <column> = <value> 
 where <conditions>

请参阅有关更新的文档:
http://download.oracle.com/docs /cd/B19306_01/server.102/b14200/statements_10007.htm#i2067715

Your update statement does not follow the correct syntax. There is no from clause in the update statement. It should follow the format

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文