DBAsupport.com Forums - Powered by vBulletin
Results 1 to 9 of 9

Thread: calling a cmd file from pl/sql

Threaded View

  1. #9
    Join Date
    Sep 2005
    Posts
    278
    Here is the java class u can use to run any OS command:

    Code:
    CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED Command 
    AS
    import java.io.*;
    import java.util.*;
    public class Command{
    public static void run(String cmdText) 
                         throws IOException, InterruptedException
    {
      int rtn;
           Runtime rt = Runtime.getRuntime();
      Process prcs = rt.exec(cmdText);
      rtn =  prcs.waitFor();
    }
    }
    Then you can publish a PL/SQL procedure to be used in ur applications.

    Code:
    CREATE OR REPLACE PROCEDURE runoscommand(cmd IN VARCHAR2)
    AS LANGUAGE JAVA
    NAME 'Command.run(java.lang.String)'

    Now you can use the above procedure to run any batch files:

    For example to unzip files:

    Code:
    CREATE OR REPLACE PROCEDURE unzipfiles(pdirname IN VARCHAR2, 
                    pfilename IN VARCHAR2, poutdirname IN VARCHAR2)
    IS
        loscmd  VARCHAR2(120);
    BEGIN
      loscmd := 'f:\data\7za e -o' || pdirname || ' ';
      loscmd := loscmd || poutdirname || ' ' || pfilename;
      runoscommand(loscmd);
    END;
    Hope this example will be helpful.
    Last edited by tabreaz; 09-14-2006 at 04:54 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width