我正在尝试更新表格,但我无法使用我的语法。我将临时表中的新元素添加到元素表中,我想更新metadata_attribute中的column_name和metadata_table表中的table_name。这就是我所拥有的:
UPDATE METADATA_ATTRIBUTE
SET C.ELEMENT_ID = (SELECT ELEMENT_ID
FROM ELEMENT A , TEMP B
WHERE A.ELEMENT_NAME = B.WMIS_COLUMN_NAME)
FROM ELEMENT A, TEMP B, METADATA_ATTRIBUTE C, METADATA_TABLE D
WHERE C.COLUMN_NAME = B.WMIS_COLUMN_NAME
AND D.TABLE_NAME = B.WMIS_TABLE_NAME
AND ELEMENT_ID IS NULL;
答案 0 :(得分:3)
从单个更新语句更新两个表在oracle 中无法实现。
您需要编写 PL / SQL块(过程或触发器)来解决此问题。
如果您需要更多帮助,请详细说明您的问题。
答案 1 :(得分:1)
尝试此操作会发生什么?
update a set a.element_id = b.element_id
from element a, temp b, metadata_attribute c, metadata_table d
where c.column_name = b.wmis_column_name and
d.table_name = b.wmis_table_name and
element_id is null;
答案 2 :(得分:1)
试试这个:
UPDATE METADATA_ATTRIBUTE m
SET m.ELEMENT_ID = /* changed C to m */
(SELECT ELEMENT_ID /* this query must not return multiple rows! */
FROM ELEMENT A , TEMP B
WHERE A.ELEMENT_NAME = B.WMIS_COLUMN_NAME
)
where m.rowid in /* I added this line */
(select C.rowid
FROM ELEMENT A, TEMP B, METADATA_ATTRIBUTE C, METADATA_TABLE D
WHERE C.COLUMN_NAME = B.WMIS_COLUMN_NAME
AND D.TABLE_NAME = B.WMIS_TABLE_NAME
AND ELEMENT_ID IS NULL
/* the ELEMENT table is not explicitly joined to any table - Carteansan Product!!!*/
);
这将更新METADATA_ATTRIBUTE表中的行。