在特定日期时间从Oracle数据库检索数据,然后将它们发布到php中的firebase

问题描述 投票:1回答:1

描述项目构想:

我正在研究在Oracle数据库8i版本上运行的系统。我想执行一个每月自动运行的查询(使用php或java)从下个月的某些用户检索到一些应付款的数据,然后将这些数据发布到google Firebase。

描述我的问题:

我不想通过单击按钮或手动运行脚本来手动运行代码,而是想知道如何在每个月的特定日期自动执行查询。用于从Oracle检索数据和将数据发布到Firebase。但不要永远循环使用服务器上的处理器。

我不知道它是否可以在PHP代码中完成,或者我应该使用外部程序或服务在特定时间自动运行我的功能

一个示例伪代码:

一个非常简单的例子来解释我的过程,实际的代码会更有条理。你的想法非常感激

// some Proramming language API to call myFunction() automatically 
/* this is what I need  */

// check date
if (today() = 20-currentMonth-currentYear)
(
   myFunction()
)

function myFunction()
{ 
  //conneting to database
  connect to oracle(connectionURL, username, password)
  // running connection
  run connection

  // executing updated query
  execute query(Select * from tableName where date 01-nextMonth-currentYear)

  // fetching query results
  Loop throw query result

  // prepare JSON format
  add result to json(object or array)

  // close database connection
  close oracle connection


  // sending json to firebase
  send json result to Firebase RestAPI
}

编程语言:

PHP

php oracle oracle8i
1个回答
2
投票

天哪,8i?那是一个古老的软件。

无论如何:您不需要PHP也不需要外部程序 - 您只需要在数据库中安排作业。 DBMS_JOB应该这样做。这是该软件包的8i文档:https://docs.oracle.com/cd/A87860_01/doc/server.817/a76956/jobq.htm#5727

这是一个如何做到这一点的例子:

SQL> set serveroutput on
SQL> -- creating a dummy procedure; yours would collect data
SQL> create or replace procedure p_test
  2  is
  3  begin
  4     null;
  5  end p_test;
  6  /

Procedure created.

SQL> -- schedule a job. NEXT_DATE says when it is executed for the first time,
SQL> -- while INTERVAL says when to re-execute it -> monthly, on 5th of every month,
SQL> -- at 14:30 
SQL> declare
  2     x   number;
  3  begin
  4     sys.dbms_job.submit (
  5        job         => x,
  6        what        => 'p_test;',
  7        next_date   => to_date ('05.12.2017 14:30:00', 'dd.mm.yyyy hh24:mi:ss'),
  8        interval    => 'add_months(to_date(''05.12.2017'', ''dd.mm.yyyy''), 1) + 14 / 24 + 30 / (24*60)',
  9        no_parse    => false);
 10     sys.dbms_output.put_line ('Job Number is: ' || to_char (x));
 11     commit;
 12  end;
 13  /
Job Number is: 2895612

PL/SQL procedure successfully completed.

SQL> -- check job info
SQL> select * from user_jobs where job = 2895612;

现在,这就是如何收集数据。不幸的是,我不知道如何将其转移到Firebase中(如果必须的话,我会提到以下关键字:数据库链接,异构服务。或者谷歌,当然)。希望其他人能够提供帮助。

© www.soinside.com 2019 - 2024. All rights reserved.