简体   繁体   English

如何在Oracle中将增量记录从一个表转移到另一个表

[英]How to transfer delta records from one table to another in oracle

I have one table t1 with attributes 我有一个带有属性的table t1

emp_joined_date,
emp_name,
emp_number.

and I want to transfer this table to another table t2(having same structure) . 我想将此表转移到另一个表t2(having same structure)

during 1st attempt I will transfer whole table but later I want to transfer only delta records from table t1 to t2 . 在第一次尝试期间,我将转移整个表,但是稍后我只想将delta records从表t1 to t2

So how do I insert multiple records from table t1 to t2 in single query(in oracle) 那么如何在单个查询中从表t1到t2插入多个记录(在oracle中)

What about this: 那这个呢:

insert into t1
select * from t2
where emp_number not in 
(select t2.emp_number from t2 join t1 on t1.emp_number = t2.emp_number) ;

If you get new records in t1 and you want to insert only those in t2 , then use this. 如果您在t1获得了新记录,并且只想在t2插入那些记录,则可以使用它。 It will give you new emp_number 它会给你新的emp_number

insert into t2 (emp_joined_date,emp_name,emp_number)
select t1.emp_joined_date,t1.emp_name,t1.emp_number 
from t1 left join t2
on t1.emp_number=t2.emp_number
where t2.emp_number is null

If you want to insert records based on time, then use this Use NVL function so for the first run, it would copy everything. 如果要基于时间插入记录,请使用此Use NVL函数,以便在首次运行时将复制所有内容。

insert into t2 (emp_joined_date,emp_name,emp_number)
select emp_joined_date,emp_name,emp_number from t1 
where emp_joined_date > 
nvl((select max(emp_joined_date) from t1),to_date('1900-01-01','YYYY-MM-DD'))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 Oracle 中一张表的所有数据传输到另一张表? - How to transfer all data from one table to another table in Oracle? Oracle SQL:根据条件将某些记录从一个表转移到另一个过滤行 - Oracle SQL: Transfer certain records from one table to another filtering rows based on condition 将记录从一个数据库上的表复制到另一个 Oracle SQL 开发人员 - COPY records from table on one database to another Oracle SQL Developer 如何遍历记录然后搜索到另一个表,如果没有找到,然后在从 oracle 中的另一个表中获取记录后插入它? - How to loop over records and then search into another table and if not found then insert it after fetching records from another table in oracle? 如何创建将数据从一个表传输到另一个表的触发器 - How to create trigger that transfer data from one table to another tabke 如何使用 airflow 将数据从一个 oracle 数据库传输到另一个 oracle 数据库 - How do I transfer data from one oracle database to another oracle database with airflow 在ORACLE中将6000000条记录从一个表插入到另一个表的最佳方法是什么? - What is the best way to insert 6000000 records from one table to another table in ORACLE? 如何在oracle中将数据从一个表插入到另一个表 - How to insert data from one table to another table in oracle 如何将 CLOB 数据从一个数据库传输到另一个具有 DBLinks 的远程 ORACLE 数据库 - how to transfer CLOB data from one database to another remote ORACLE database having DBLinks 使用复合键在 Oracle 表中进行 20 亿条记录的增量检测 - Delta Detection in Oracle table with 2 billion records using composite key
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM