首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

oracle中,依据B表的新部门更改A表的旧部门

2012-07-30 
oracle中,-根据B表的新部门更改A表的旧部门create table A(BADEPTID VARCHAR2(30) not null, --旧部门编码

oracle中,-根据B表的新部门更改A表的旧部门
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);

热点排行