Home > Software engineering >  how to run an exe file with given parameters in pl\sql oracle db
how to run an exe file with given parameters in pl\sql oracle db

Time:12-15

i am transfroming oracle forms codes to oracle stored procedure so i need your helps. can anybody tell me how to run an exe file with parameters in plsql code? i have tried many ways to do it. you can see sample code of it below.

here is my code

DECLARE
  v_onay NUMBER;
  CURSOR c1 IS
    SELECT id
      FROM t1
     WHERE tarih = :main.tarih
       AND creditid IN
           (SELECT kredid FROM t2 WHERE tarih = :main.tarih)
     ORDER BY id;
  AppID PLS_INTEGER;
BEGIN
  v_onay := sor('GİRİLEN TARİH İÇİN GEÇ YAPILAN ÖDEMELERİ TEKRAR ÇALIŞTIRMAK İSTİYOR MUSUNUZ? ');
  IF v_onay = 1 THEN
    entegre.Krdtfrs9_Doldur(1, :main.tarih);  
    mess('Kayıtlar güncellendi. OUTPUT verileri hazırlanacak', 0);
  
    FOR r1 in c1 LOOP
      COMMIT;
    
      AppID := DDE.App_Begin('C:\Muhasebe\tfrs\Krd\ID\TFRS9KRD_ID.exe ' ||
                             TO_CHAR(:main.tarih, 'DD.MM.YYYY') || ' ' ||r1.id,
                             DDE.App_Mode_Maximized);    
    END LOOP;  
  END IF;
  mess('Güncelleme tamamlandı', 0);
END;

thanks a lot.

CodePudding user response:

As far as I can tell, if you want to run an operating system executable file from PL/SQL stored procedure, you'd schedule it using the DBMS_SCHEDULER built-in package.

Something like this:

You'd pass tarih and id as procedure's parameters.

SQL> CREATE OR REPLACE PROCEDURE p_exe (par_tarih DATE, par_id NUMBER)
  2  AS
  3     l_name   VARCHAR (20) := 'GUNES';
  4     l_tarih  VARCHAR2 (10) := TO_CHAR (par_tarih, 'dd.mm.yyyy');
  5  BEGIN
  6     -- drop job if it already exists
  7     BEGIN
  8        DBMS_SCHEDULER.drop_job (l_name);
  9     EXCEPTION
 10        WHEN OTHERS
 11        THEN
 12           NULL;
 13     END;
 14
 15     -- create a new job
 16     DBMS_SCHEDULER.create_job (
 17        job_name             => l_name,
 18        job_type             => 'EXECUTABLE',
 19        job_action           => 'C:\Muhasebe\tfrs\Krd\ID\TFRS9KRD_ID.exe',
 20        number_of_arguments  => 2,
 21        enabled              => FALSE);
 22
 23     -- set arguments
 24     DBMS_SCHEDULER.set_job_argument_value (job_name           => l_name,
 25                                            argument_position  => 1,
 26                                            argument_value     => par_tarih);
 27     DBMS_SCHEDULER.set_job_argument_value (job_name           => l_name,
 28                                            argument_position  => 2,
 29                                            argument_value     => par_id);
 30
 31     -- enable job
 32     DBMS_SCHEDULER.enable (l_name);
 33  END;
 34  /

Procedure created.

SQL>
  • Related