Link to home
Start Free TrialLog in
Avatar of mkwdrs
mkwdrs

asked on

Oracle 8i - continuous running procedure

I need to do the following:

Create a stored procedure that will reside in an Oracle 8i database running on Windows 2000.  This procedure needs to be running at all times when the database is running.  The purpose of the procedure is to execute a query on some SQL Server tables via the SQL Server gateway.  (SQL Server 6.5 is also running on Windows 2000).  If new records are found in the SQL Server tables, then execute more Oracle procedures/functions.  This query needs to be ran every 5 to 10 seconds to check and see if new records exist.  If the Oracle database goes down, this procedure needs to be started immediately after the database is available.  If the SQL Server connection is lost for any reason, a new connection needs to be created.  Any advice on how best to accomplish this task.
Avatar of schwertner
schwertner
Flag of Antarctica image

To schedule when to run subprograms use the Oracle Supplied Package DBMS_JOB:

SUBMIT Procedure
This procedure submits a new job. It chooses the job from the sequence sys.jobseq.

Syntax
DBMS_JOB.SUBMIT (
   job       OUT BINARY_INTEGER,
   what      IN  VARCHAR2,
   next_date IN  DATE DEFAULT sysdate,
   interval  IN  VARCHAR2 DEFAULT 'null',
   no_parse  IN  BOOLEAN DEFAULT FALSE,
   instance  IN  BINARY_INTEGER DEFAULT any_instance,
   force     IN  BOOLEAN DEFAULT FALSE);

Parameters
Table 17-2 SUBMIT Procedure Parameters
Parameter  Description  
job

  Number of the job being run.
 
what

  PL/SQL procedure to run.
 
next_date

  Next date when the job will be run.
 
interval

  Date function that calculates the next time to run the job. The default is NULL. This must evaluate to a either a future point in time or NULL.  
 
no_parse

  A flag. The default is FALSE. If this is set to FALSE, then Oracle parses the procedure associated with the job. If this is set to TRUE, then Oracle parses the procedure associated with the job the first time that the job is run.

For example, if you want to submit a job before you have created the tables associated with the job, then set this to TRUE.  
 
instance

  When a job is submitted, specifies which instance can run the job.
 
force

  If this is TRUE, then any positive integer is acceptable as the job instance. If this is FALSE (the default), then the specified instance must be running; otherwise the routine raises an exception.
 
 

Usage Notes
The parameters instance and force are added for job queue affinity. Job queue affinity gives users the ability to indicate whether a particular instance or any instance can run a submitted job.

Example
This submits a new job to the job queue. The job calls the procedure DBMS_DDL.ANALYZE_OBJECT to generate optimizer statistics for the table DQUON.ACCOUNTS. The statistics are based on a sample of half the rows of the ACCOUNTS table. The job is run every 24 hours:

VARIABLE jobno number;
BEGIN
   DBMS_JOB.SUBMIT(:jobno,
      'dbms_ddl.analyze_object(''TABLE'',
      ''DQUON'', ''ACCOUNTS'',
      ''ESTIMATE'', NULL, 50);'
      SYSDATE, 'SYSDATE + 1');
   commit;
END;
/
Statement processed.
print jobno
JOBNO
----------
14144


No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
 - PAQ'd and pts removed
Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

Nic;o)
ASKER CERTIFIED SOLUTION
Avatar of Netminder
Netminder

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial