oracle_将一个数据库的某一张表复制到另一个数据库(表名与表结构结构相同,数据库不同)

好了2020 / 2023-05-23 / 原文

1.不同数据库
数据库:数据库A表名:student 数据库A的库名:school_A
数据库B表名:student

insert into student
--要把数据插入数据库B中的student表
select * from student@school_A
--数据库A:school_A 中的student表(注意1:school_A需要是登录状态    注意2:输入@时,一般会有提示,也可根据提示选择对应的数据库)
where rownum <=500;
--数据库A的student表的前500个数据,如不写,代表整张表的数据全部复制到A表
commit; 
--提交 

(写成四行,便于区分。 如果提示有错误字符,把所有的注释删除)

2.同一数据库
insert into 目标表 select * from 源表; --将 源表 的数据复制到 目标表

3.将同一张表的字段数据插入到另一张表的字段数据中
insert into test2(name,age) select name,age from test1;
将test1 name 和 age 字段的值插入test2 name 和 age 字段

4.将同一张test表的字段A的值复制到字段B中
update test set B = A;