ORA-38104:无法更新 ON 子句中引用的列 c.emp_id [英] ORA-38104: Columns referenced in the ON Clause cannot be updated c.emp_id
本文介绍了ORA-38104:无法更新 ON 子句中引用的列 c.emp_id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两张简单的桌子
CREATE TABLE 员工 (emp_id INT PRIMARY KEY,名字 VARCHAR(40),姓氏 VARCHAR(40),生日日期,性别 VARCHAR(1),工资INT,super_id INT,branch_id INT);创建表生物数据(emp_id INT PRIMARY KEY,名字 VARCHAR(40),姓氏 VARCHAR(40),生日日期,性别 VARCHAR(1));
我想合并它
合并到biodata c使用员工 e在 (c.emp_id = e.emp_id)当匹配然后更新集c.emp_id=e.emp_id,c.first_name=e.first_name,c.last_name=e.last_name,c.birth_day=e.birth_day,c.sex=e.sex当不匹配时插入值(e.emp_id,e.first_name,e.last_name,e.birth_day,e.sex);
但甲骨文说:
<块引用>ORA-38104:ON 子句中引用的列无法更新:c.emp_id
解决方案
只需将 c.emp_id=e.emp_id
从 UPDATE
子句中删除,因为它无关紧要>
(UPDATE
将对满足条件 c.emp_id = e.emp_id
的表 biodata
的记录进行.所以将要更新的记录已经具有与 e.emp_id
相同的 emp_id
).
合并到biodata c使用员工 e在 (c.emp_id = e.emp_id)当匹配然后更新集--c.emp_id=e.emp_id,c.first_name=e.first_name,c.last_name=e.last_name,c.birth_day=e.birth_day,c.sex=e.sex当不匹配时插入值(e.emp_id,e.first_name,e.last_name,e.birth_day,e.sex);
干杯!!
i have 2 simple table
CREATE TABLE employee (
emp_id INT PRIMARY KEY,
first_name VARCHAR(40),
last_name VARCHAR(40),
birth_day DATE,
sex VARCHAR(1),
salary INT,
super_id INT,
branch_id INT
);
CREATE TABLE biodata (
emp_id INT PRIMARY KEY,
first_name VARCHAR(40),
last_name VARCHAR(40),
birth_day DATE,
sex VARCHAR(1)
);
i want to merge it
merge into biodata c
using employee e
on (c.emp_id = e.emp_id)
when matched then
update set
c.emp_id=e.emp_id,
c.first_name=e.first_name,
c.last_name=e.last_name,
c.birth_day=e.birth_day,
c.sex=e.sex
when not matched then
insert VALUES(e.emp_id,e.first_name,e.last_name,e.birth_day,e.sex);
but Oracle says:
ORA-38104: Columns referenced in the ON Clause cannot be updated: c.emp_id
解决方案
Just remove the c.emp_id=e.emp_id
from UPDATE
clause as it is irrelevant
(UPDATE
will be done on the record of table biodata
for which condition c.emp_id = e.emp_id
is satisfied. so the record which is going to be updated already have the same emp_id
as e.emp_id
).
merge into biodata c
using employee e
on (c.emp_id = e.emp_id)
when matched then
update set
--c.emp_id=e.emp_id,
c.first_name=e.first_name,
c.last_name=e.last_name,
c.birth_day=e.birth_day,
c.sex=e.sex
when not matched then
insert VALUES(e.emp_id,e.first_name,e.last_name,e.birth_day,e.sex);
Cheers!!
这篇关于ORA-38104:无法更新 ON 子句中引用的列 c.emp_id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文