create table A
(
BADEPTID VARCHAR2(30) not null, --旧部门编码
ID NUMBER not null
);
alter table A
add constraint ID_PK primary key (ID);
create table B
(
OLD_DEPT VARCHAR2(4000) not null,--旧部门编码
NEW_DEPT VARCHAR2(200) not null --新部门编码
);
alter table B
add constraint TEMP_PK primary key (OLD_DEPT, NEW_DEPT);
--根据B表的新部门更改A表的旧部门
Update A aa
Set aa.badeptid = (Select ab.new_dept From B ab Where ab.old_dept = aa.badeptid)
Where Exists (Select 1 From B ab Where ab.Old_dept = aa.badeptid);
(
BADEPTID VARCHAR2(30) not null, --旧部门编码
ID NUMBER not null
);
alter table A
add constraint ID_PK primary key (ID);
create table B
(
OLD_DEPT VARCHAR2(4000) not null,--旧部门编码
NEW_DEPT VARCHAR2(200) not null --新部门编码
);
alter table B
add constraint TEMP_PK primary key (OLD_DEPT, NEW_DEPT);
--根据B表的新部门更改A表的旧部门
Update A aa
Set aa.badeptid = (Select ab.new_dept From B ab Where ab.old_dept = aa.badeptid)
Where Exists (Select 1 From B ab Where ab.Old_dept = aa.badeptid);
本文介绍如何使用SQL语句实现根据B表中新部门编码更新A表中旧部门编码的操作,包括创建表、添加主键约束、执行更新查询。
1万+

被折叠的 条评论
为什么被折叠?



