我试图通过将值与另一个表连接来更新表。以下是我目前的查询。
UPDATE LOGIN SET LOGIN.DISABLED_IND = 'N', LOGIN.DREASON = 'Test'
FROM CONTACT
WHERE CONTACT.CONTACT_ID = LOGIN.CONTACT_ID
AND CONTACT.RID ='abc'
当我运行这个,我得到这个
[Error Code: 933, SQL State: 42000] ORA-00933: SQL command not properly ended
谢谢
如果您希望更新LOGIN
中的大部分行,那么使用EXISTS
UPDATE LOGIN l
SET l.DISABLED_IND = 'N',
l.DREASON = 'Test'
WHERE EXISTS (
SELECT 1
FROM CONTACT c
WHERE c.CONTACT_ID = l.CONTACT_ID
AND c.RID ='abc' )
如果您在LOGIN
中更新相对较少的行,那么Yahia使用in的方法可能会更有效
UPDATE LOGIN l
SET l.DISABLED_IND = 'N',
l.DREASON = 'Test'
WHERE l.contact_id IN (
SELECT c.contact_id
FROM CONTACT c
WHERE c.RID ='abc' )
try
UPDATE LOGIN L SET L.DISABLED_IND = 'N', L.DREASON = 'Test'
WHERE L.CONTACT_ID
IN ( SELECT C.CONTACT_ID FROM CONTACT C WHERE C.CONTACT_ID = L.CONTACT_ID AND
C.RID='abc');
另一个更复杂的选项见http://geekswithblogs.net/WillSmith/archive/2008/06/18/oracle-update-with-join-again.aspx
您的语法不太正确。这篇维基百科文章有很多例子供您选择。
例如UPDATE l
SET l.DISABLED_IND = 'N', l.DREASON = 'Test'
FROM LOGIN l
JOIN CONTACT c
ON c.CONTACT_ID = l.CONTACT_ID AND c.RID ='abc'