A表有字段
id,name,ip,b_id
B表有字段id,ip想实现查询A表所有数据,并根据ip字段信息对应查询B表的id,把查询出来的B表ID对应插入到 A 表中的b_id字段中比如有IP查询函数 IPSESRCH();
id,name,ip,b_id
B表有字段id,ip想实现查询A表所有数据,并根据ip字段信息对应查询B表的id,把查询出来的B表ID对应插入到 A 表中的b_id字段中比如有IP查询函数 IPSESRCH();
你仿照着写一下
SQL> create table t1(id int,ip int);Table created.SQL> create table t2(id int,ip int);Table created.SQL> insert into t1 values(1,2);1 row created.SQL> insert into t1 values(2,3);1 row created.SQL> insert into t2 values(7,3);1 row created.SQL> insert into t2 values(9,5);1 row created.SQL> commit;Commit complete.SQL> select * from t1; ID IP
---------- ----------
1 2
2 3SQL> select * from t2; ID IP
---------- ----------
7 3
9 5
SQL> update t1
2 set id = (select id from t2 where t1.ip = t2.ip)
3 where exists (select 1 from t2 where t1.ip = t2.ip);1 row updated.SQL> select * from t1; ID IP
---------- ----------
1 2
7 3 --这条记录的id字段被更改了SQL>