创建两个表,并插入数据
create table t11 (
name varchar2(255),
color varchar2(255)
);
insert into t11 (name ,color )values('猪猪','白色') ;
commit;
insert into t11 (name ,color )values('羊羊','红色') ;
commit;
select * from t11 ;
create table t22 (
name varchar2(10),
color varchar2(10)
);
insert into t22 ?(name,color)values('猪猪','粉色') ;
commit;
insert into t22 ?(name,color)values('牛牛','黄色') ;
commit;
insert into t22 ?(name,color)values('兔兔','白色') ;
commit;
select * from t22;
根据name把t11表中的color更新成t22表里对应的颜色
UPDATE t11?
SET t11.color = (select t22.color from t22 where t22.name = t11.name)
WHERE EXISTS(SELECT 1 FROM t22 WHERE t22.name = t11.name);
commit;
这样t11表里猪猪的颜色就从白色变成了粉色