简体   繁体   English

每天将查询结果从oracle数据库存储到MySql数据库中

[英]Storing query result from oracle database into MySql database on daily basis

My application has 2 databases, Oracle and MySQL. 我的应用程序有2个数据库,Oracle和MySQL。 Now I need to store query result from table in oracle database into a table into MySQL database after every few hours. 现在,每隔几个小时,我需要将oracle数据库中的表的查询结果存储到MySQL数据库中的表中。

Here is the image that describes the above scenario. 这是描述上述情况的图像。

I checked other similar questions but they are mostly on migration of entire database from Oracle to MySql not for "query result after every few hours" . 我检查了其他类似的问题,但它们主要是关于将整个数据库从Oracle迁移到MySql,而不是“每隔几个小时就会查询结果”。

What is the best way to achieve this? 实现此目标的最佳方法是什么?

I would do this by creating a DB link from the Oracle server to the MySQL server. 我可以通过创建从Oracle服务器到MySQL服务器的数据库链接来做到这一点。 It's a bit involved, but once you have that working, you should be able to create a scheduler job to run the query every few hours and insert the results into a table over the DB link. 它涉及到一点,但是一旦完成工作,您就应该能够创建一个调度程序作业,每隔几个小时运行一次查询,并将结果插入数据库链接上的表中。

begin
dbms_scheduler.create_job (
   job_name           =>  'store_my_result',
   job_type           =>  'PLSQL_BLOCK',
   job_action         =>  'BEGIN insert into "my_table"@mysqldblink select * from TestA; END;',
   start_date         =>  '05-Dec-2018 07:00:00 am',
   repeat_interval    =>  'FREQ=HOURLY;INTERVAL=3',
   enabled            =>  true);
end;
/

Obviously, test your anonymous PL/SQL block separately before creating a job using it. 显然,在使用它创建作业之前,请分别测试您的匿名PL / SQL块。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM