oracle同步数据,两张表结构相同且分布在不同数据库,具体场景如下,如何写SQL语句?
oracle同步数据,两张表结构相同且分布在不同数据库(比如A.a表和B.a表),且两张表已经有部分数据是一样的,现在是一张表还在增长数据(A.a),另一张表需要建数据同...
oracle同步数据,两张表结构相同且分布在不同数据库(比如A.a表和B.a表),且两张表已经有部分数据是一样的,现在是一张表还在增长数据(A.a),另一张表需要建数据同步过来(需要将A.a同步到B.a)。如何写SQL语句?
展开
2个回答
展开全部
异构数据库的话,用db_link 和 Merge 吧
语法如下 :
MERGE INTO [your table-name] [rename your table here]
USING ( [write your query here] )[rename your query-sql and using just like a table]
ON ([conditional expression here] AND [...]...)
WHEN MATHED THEN [here you can execute some update sql or something else ]
WHEN NOT MATHED THEN [execute something else here ! ]
大概如下:
merge into B.a@db_link_name t2 using A.a t1 on (t1.xxxx = t2.xxxx)
when not matched then
insert values(t1.xxxx, t1.yyy, t1.zzz) l
语法如下 :
MERGE INTO [your table-name] [rename your table here]
USING ( [write your query here] )[rename your query-sql and using just like a table]
ON ([conditional expression here] AND [...]...)
WHEN MATHED THEN [here you can execute some update sql or something else ]
WHEN NOT MATHED THEN [execute something else here ! ]
大概如下:
merge into B.a@db_link_name t2 using A.a t1 on (t1.xxxx = t2.xxxx)
when not matched then
insert values(t1.xxxx, t1.yyy, t1.zzz) l
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询