Oracle 11g SQL&两个表都有相同的列定义:
VARCHAR2(11)
NUMBER
DATE
DATE
我试图找到解决这个问题的方法,这就是我最终的结果,但是失败了:
update jjjTable
set [fourthCol] = B.[fourthOtherCol]
from jjjTable, otherTable B
where jjjTable.[firstCol] = B.[firstOtherCol]
and jjjTable.[secondCol] = B.[secondOtherCol]
and jjjTable.[thirdCol] = B.[thirdOtherCol]
我的印象是我需要在此基础上使用此文章:
SQL update from one Table to another based on a ID match以及Shivkant编辑的回复
我的印象是我可能需要根据这篇文章使用联接:
How do I UPDATE from a SELECT in SQL Server?以及Robin Day的回复
但据我了解,连接只是每行一列匹配。我对3个元素的匹配感兴趣,而且我找不到明确的解决方案。
任何方向都会受到欢迎。
答案 0 :(得分:0)
这是我最终需要做的解决方案:
DECLARE
CURSOR j_CUR IS
SELECT A.[fourthCol]
FROM JJJtable A, otherTable B
WHERE A.[firstCol] = B.[firstOtherCol]
and A.[secondCol] = B.[secondOtherCol]
and A.[thirdCol] = B.[thirdOtherCol]
FOR UPDATE OF B.[fourthOtherCol];
SOME_DATE DATE;
BEGIN
FOR IDX IN j_CUR LOOP
SOME_DATE :=(IDX.[fourthCol]);
UPDATE otherTable
SET [fourthOtherCol] = SOME_DATE
WHERE CURRENT OF j_CUR;
END LOOP;
END;
感谢您的努力和指导。