SQL命令未正确结束错误;尝试通过联接更新信息

时间:2018-07-23 15:38:09

标签: sql oracle

UPDATE A
SET A.email_from = B.new_email_from
FROM email_list A 
INNER JOIN update B 
    ON A.email_subject = B.email_subject 
WHERE A.process = B.process;

我正在尝试使用另一个表包含的更新信息来更新一个表。我不确定为什么它会一直给我这个错误。

ORA-00933: SQL command not properly ended

3 个答案:

答案 0 :(得分:2)

一个简单的MERGE就可以了

MERGE INTO a 
USING b 
ON ( a.email_subject = b.email_subject ) 
WHEN matched THEN 
  UPDATE SET a.email_from = b.new_email_from 
WHERE a.process = b.process; 

答案 1 :(得分:0)

您的Oracle语法无效。在UPDATE上执行JOIN应该更简单,但这就是事实。

尝试类似的东西:

UPDATE 
  ( 
    SELECT A.email_from, B.new_email_from
    FROM email_list A 
    INNER JOIN update B ON A.email_subject = B.email_subject 
        AND A.process = B.process
) s1
SET s1.email_from = s1.new_email_from

答案 2 :(得分:0)

您好@RemoveBeforeFight,

请尝试使用相关子查询进行更新。

update a set A.email_from = (
  select B.new_email_from 
    from update B 
    where a.email_subject = b.email_subject 
    and A.process = B.process
);