gpt4 book ai didi

sql - ORA-38104 : Columns referenced in the ON Clause cannot be updated c. emp_id

转载 作者:行者123 更新时间:2023-12-03 08:00:23 25 4
gpt4 key购买 nike

我有2个简单的表格

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)
);

我想合并它

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);

但是甲骨文说:

ORA-38104: Columns referenced in the ON Clause cannot be updated: c.emp_id

最佳答案

只需从 UPDATE 子句中删除 c.emp_id=e.emp_id,因为它是不相关的

(UPDATE 将在满足条件 c.emp_id = e.emp_id 的表 biodata 的记录上完成。所以将要更新的记录已经具有与 e.emp_id 相同的 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);

干杯!

关于sql - ORA-38104 : Columns referenced in the ON Clause cannot be updated c. emp_id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59550274/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com