SQL> create table t1(id int,name varchar2(10));
Table created.
SQL> create table t2(id int,name varchar2(10));
Table created.
SQL> insert into t1 values(1,'a');
1 row created.
SQL> insert into t1 values(2,'b');
1 row created.
SQL> insert into t2 values(3,'c');
1 row created.
SQL> insert into t2 values(2,'d');
1 row created.
SQL> select * from t1;
ID NAME
---------- ----------
1 a
2 b
SQL> select * from t2;
ID NAME
---------- ----------
3 c
2 d
SQL> update t1 set name =(select name from t2 where t1.id=t2.id);
2 rows updated.
SQL> select * from t1;
ID NAME
---------- ----------
1
2 d
SQL> delete from t1;
2 rows deleted.
SQL> delete from t2;
2 rows deleted.
SQL> insert into t1 values(1,'a');
1 row created.
SQL> insert into t1 values(2,'b');
1 row created.
SQL> insert into t2 values(3,'c');
1 row created.
SQL> insert into t2 values(2,'d');
1 row created.
SQL> update t1 set name =(select name from t2 where t1.id=t2.id) where exists(select 1 from t2 where t1.id=t2.id);
1 row updated.
SQL> select * from t1;
ID NAME
---------- ----------
1 a
2 d
oracle 多表关联更新为什么要加exists
最新推荐文章于 2024-07-22 15:27:09 发布