Calling external program from PL/SQL

Does anyone know whether it's possible to call an external program living outside of Oracle from PL/SQl eg. a from a stored procedure?
Specifically i want to call back into my java appserver (ejb server) when a trigger/stored proc. is executed.
The call does not have to be synchronous, some sort of queue will do - eg JMS??
Any help greatly appreciated.
null

Hi
Which version of oracle you are using.
If it 8i, you can use external procedures/libraries. REfer to ORacle PLSQL documentation.
If you are using Oracle 7+ you can use dbms pipes to post your command string and a cron job to read the pipe and execute the string.
An alternate ugly way is to write to a file and some process reading the file at a regular interval.
HTH
Arvind Balaraman

Similar Messages

  • Call C++ programs from PL/SQL

    Can someone give me an example of how to call C++ programs from PL/SQL ASAP please?
    Thanks
    Chitra

    Hello,
    You can use External Procedure facility of of PL/SQL (Assuming your DB is 8 or 8i)
    Please refer the doc at http://oradoc.photo.net/ora8doc/DOC/server803/A54654_01/10_procs.htm
    James

  • Calling Cobol program from PL/SQL

    What is the caling convention for PL/SQL to call a Cobol program?

    You cannot do it directly from PL/SQL. PL/SQL is.. well, kind of abstract ito the actual platform it runs on. PL/SQL cannot talk directly to operating system. It cannot (itself) do socket calls, file I/O calls, use the printer, etc.
    <p>
    All this has to be done using a lower level implementation library - like UTL_FILE for example that wraps internal C written modules that does file I/O. PL/SQL can call these to do I/O on its behalf. Ditto for wrappers like UTL_TCP and others.
    <p>
    There is no default wrapper for calling external processes from PL/SQL. It can however be done indirectly using the external procedure (EXTPROC) feature, or using Java to do it.
    <p>
    The latter is the easiest. You create a Java stored proc that can access the operating system and run external programs and commands. You punch a big hole in the Oracle Java security to allow this Java stored proc access to the operating system. Next you create a PL/SQL wrapper for this Java proc which then in turn can be called from PL/SQL.
    Just remember that you MUST secure this hole you've punched into Oracle security. If any Oracle user can access this PL/SQL wrapper, they can hack, compromise, trash or simply destroy your entire Oracle account on that server.
    Here is the basic code:
    create or replace and compile Java Source named "OSCommand" as
    -- java:        OS COMMAND
    -- descr:       Executes an Operating System Command using the JAVA RTS
    -- IN parameter:        os command to execute (including fully qualified path names)
    -- OUT parameter:       returncode [\nstring]
    --                      where string a max of 32000 chars of the output of the command
    --                      (note that \n is used as separators in the string)
    --                      returncode=-1   Java RTS error occurred (e.g. command does not exist)
    --                      returncode=255  o/s command failed (e.g. invalid command params)
    import java.io.*;
    import java.lang.*;
    public class OSCommand{
            public static String Run(String Command){
                    Runtime rt = Runtime.getRuntime();
                    int     rc = -1;
                    try{
                            Process p = rt.exec( Command );
                            int bufSize = 32000;
                            int len = 0;
                            byte buffer[] = new byte[bufSize];
                            String s = null;
                            BufferedInputStream bis = new BufferedInputStream( p.getInputStream(), bufSize );
                            len = bis.read( buffer, 0, bufSize );
                            rc = p.waitFor();
                            if ( len != -1 ){
                                    s = new String( buffer, 0, len );
                                    return( s );
                            return( rc+"" );
                    catch (Exception e){
                            e.printStackTrace();
                            return(  "-1\ncommand[" + Command + "]\n" + e.getMessage() );
    show errors
    create or replace function OSexec( cCommand IN string ) return varchar2 is
    -- function:    OS EXEC
    -- descr:       PL/SQL wrapper for the Java OSCOMMAND stored proc
    language        JAVA
    name            'OSCommand.Run(java.lang.String) return java.lang.String';
    show errors
    -- Punching a hole into the Java VM sandbox. The following must be run as
    -- sysdba. Substitute SCOTT with the applicable schema that owns the OSEXEC
    -- and OSCOMMAND stored procs.
    declare
            SCHEMA  varchar2(30) := 'SCOTT';
    begin
            dbms_java.grant_permission(
                    SCHEMA,
                    'SYS:java.io.FilePermission',
                    '<<ALL FILES>>',
                    'execute'
            dbms_java.grant_permission(
                    SCHEMA,
                    'SYS:java.lang.RuntimePermission',
                    'writeFileDescriptor',
            dbms_java.grant_permission(
                    SCHEMA,
                    'SYS:java.lang.RuntimePermission',
                    'readFileDescriptor',
    commit;
    end;
    -- example: running the Unix/Linux date command to get the current date and time
    SQL> select OSexec('/usr/bin/date') as STDOUT from dual;
    STDOUT
    Fri Sep  1 08:09:34 SAST 2006
    1 row selected.
    SQL>Edited by: Billy Verreynne on Sep 4, 2008 6:26 PM to make the code snippet readable with the new Jive forum s/w.

  • Calling java program from PL/SQL code

    Dear,
    How to develop and call a java program from PL/SQL code?
    What about if this program will call other java programs?

    Perhaps the Java Developer's Guide would be a good place to start
    http://download.oracle.com/docs/cd/B19306_01/java.102/b14187/toc.htm
    Justin

  • Calling java program from PL/SQL

    I already have a java program that encrypts/decrypts data.
    How can I use or rather call this program in PL/SQL?

    Please refer [url http://download-west.oracle.com/docs/cd/B19306_01/appdev.102/b14261/subprograms.htm#sthref1814]Calling External Subprograms on PL/SQL User's Guide and Reference.

  • Calling external programs from within a Tomcat application

    I've got a fairly complex existing Tomcat application (which is packaged and built as a .war file) which I'm trying to edit so that it calls a Perl script part way through the processing, which will generate an XML file used later on. I think I've worked out how to call external scripts from within Java, but at the moment when I try and access the application via Tomcat the application either hangs or bails out (I don't know which, as the log files unhelpfully don't give any error messages).
    The code which is causing the problem looks like this:
    System.err.println("Calling runtime...");
    Runtime runtime = Runtime.getRuntime();
    System.err.println("Executing process...");
    Process process = runtime.exec("/path/to/ysearch.pl 'News' '\"search query\"' 'file");
    System.err.println("Waiting for process...");
    int exitVal = process.waitFor();
    System.out.println("Exited with error code: " + exitVal);The code gets as far as "Executing process..", beyond that there is nothing in the log file so I presume the runtime.exec() call is where the problem is. I'm not interested in reading the output from the script (there shouldn't be any), so that's not an issue, and the permissions on it allow anyone to read or execute ysearch.pl so I don't think there's a problem in that area.
    Does anyone have any suggestions which I could try to get this to work? I've only been using Tomcat for a week (I'm picking up on someone else's code) so I might have made a beginner's mistake. I'm using Tomcat 5 on Fedora Core 7, and Java 1.5.0_01 (I can't easily change any of those).

    I'm not sure, but I thing that overhead caused by calling du cannot be big enough to matter even on older machines.
    But, when calling du from Perl script you are also invoking shell, and this can be a little bit more 'heavy'.

  • Calling external programs from Java?

    Hi All,
    Is there a way of calling external applications from Java without using Runtime.exec(). That method seems quite messy when you are dealing with streaming data from an input file to an output file. Basically what I'm asking is there a way to run a command the same way you would type it in a command shell?
    Thanks

    LeWalrus wrote:
    Ok, I've an external application that I want to be called inside a Java GUI. It has several input arguements, which the format looks something like:
    programname inputfile > outputfile
    Simple enough.
    >
    Works fine from a shell command line. From what I understand, this won't work using Runtime.exec() because that method will just start the application. Works fine from Runtime.exec(). Since you are'>' to write stdout to a file you need to us a shell to execute the command.
    String[] command = {"sh", "-c","programname inputfile > outputfile"};
    Process process = runtime.exec(command);
    You need to read, digest and implement the recommendations given in http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html .
    File input and output from the application has to be taken care of programatically (java.io stuff). Fine if you've only one input and output. But if you have several input files and hundreds of output files, where does this leave you. It would be much easier if you could pass a string command to the shell directly as if you typed it in the command line yoursel!

  • Scenario to call c programs from pl/sql

    I know that c routines can be called from Oracle pl/sql. But, I would like to know that anybody has the realtime scenario where it is unavoidable.
    Please let me know if anybody has any specific scenarios.
    Thanks in advance
    Sudhir

    There are numerous scenarios - as Oracle is operating system agnostic (mostly) and do not provide numerous 3rd party interfaces.
    For example, you want to use MAPI (Microsoft's <i>Mail API</i>). You can write a C dll that provides an easy and basic interface into MAPI - and then define this C dll as external procedure that enables you to perform PL/SQL calls to logon to a Microsoft Exchange Server, verify and get users, send mail, enumerate the contents of a mail box's folder, read a mail, and so on.
    Or something more complex. Oracle is used by an application server that provides automated telephonic call centre support. You know - the automated system that answers your support call, asks numerous questions, gets input from you and attempts to troubleshoot your problem. Modern systems like these use speech recognition interfaces - where the caller can (using plain English) state the problem, instead of pushing tone buttons on the phone.
    Such a system will need XML templates defining the speech recognition interface context - these templates with define the basic sentence structures the caller will use, words used, assign values to the words for processing and so on. These XML templates (together with the troubleshooting data and rules) can be stored in Oracle.
    One function needed will be to verify the XML template with the speech recognition system used. Again, this can be done from PL/SQL. When a new template is entered into the database, PL/SQL can make an external proc call to a C dll that interfaces with SAPI v5 (Microsoft's <i>Speech API</i>) to compile the XML template and determine whether it is valid or not.
    There are literally 1000's upon 1000's of such scenarios that requires one to call external services and interfaces from PL/SQL - and the external proc feature of Oracle is often the technical solution that can be used to address the requirement.

  • Executing external programs from PL/SQL?

    Hi All,
    Is it possible to execute external
    programs (i.e. shell scripts, or
    perl scripts) from a stored procedure
    or trigger?
    I know that typically it is the other
    way around, but hey try telling that
    to my boss.
    Thanks

    you cant execute any operating system commands from plsql
    procedures. but you can achieve result by using either java
    stored procedure or pro*C program .
    Suresh Vemulapalli

  • How to call VB program from PL/SQL ?

    hi, i use oracle8i and i would like to call program VB from Stored procedur or PL/SQL program.
    Is it possible and how?
    thanks

    If you are trying to invoke a WebService, it shouldn't matter what under what platform that WebService compiled or where it is executing, as long as it is on a shared network. That is the very "definition" of a WebService. You should be able to invoke the webservice via TCP sockets, streaming XML message content.
    If your VB WebService isn't, in reality, a WebService and you need to invoke it as an ActiveX dll that is possible with Oracle COM Automation. The 8i/9i data server must be running on the win32 platform that has the ActiveX dll installed. I'm not sure if there is any DCOM possibilities (though I suspect not). In all circumstances, if you data server is running on a non-win32 platform, you are out of luck.
    If you are trying to invoke an ActiveX application (not a dll) from the 8i/9i data server, you are pretty much out of luck, too.
    Hope that helps,
    Michael

  • How to call Operating System commands / external programs from within APEX

    Hi,
    Can someone please suggest how to call Operating Systems commands / external programs from within APEX?
    E.g. say I need to run a SQL script on a particular database. SQL script, database name, userid & password everything is available in a table in Oracle. I want to build a utility in APEX where by when I click a button APEX should run the following
    c:\oracle\bin\sqlplusw.exe userud/password@database @script_name.sql
    Any pointers will be greatly appreciated.
    Thanks & Regards,

    Hi Guys,
    I have reviewed the option of using scheduler and javascript and they do satisfy my requirements PARTIALLY. Any calls to operating system commands through these features will be made on the server where APEX is installed.
    However, here what I am looking at is to call operating systems programs on client machine. For example in my APEX application I have constructed the following strings of commands that needs to be run to execute a change request.
    sqlplusw.exe user/password@database @script1.sql
    sqlplusw.exe user/password@database @script2.sql
    sqlplusw.exe user/password@database @script3.sql
    sqlplusw.exe user/password@database @script4.sql
    What I want is to have a button/link on the APEX screen along with these lines so that when I click that link/button this entire line of command gets executed in the same way it would get executed if I copy and paste this command in the command window of windows.
    Believe me, if I am able to achieve what I intend to do, it is going to save a lot of our DBAs time and effort.
    Any help will be greatly appreciated.
    Thanks & Regards,

  • Calling external dll from oracle 8i pl/sql

    Hi
    I am facing in calling extrenal dll from pl/sql.
    Steps followed by me are
    1.
    create library crc_lib as
    'D:\ORACLE\ORA81\RDBMS\EXTPROC\EXTPROC\my.DLL';
    2.
    CREATE OR REPLACE FUNCTION check_file_crc (f1 char)
    RETURN BOOLEAN AS
    EXTERNAL LIBRARY CRC_LIB
    NAME "Check_File_CRC"
    LANGUAGE C;
    3. CREATE OR REPLACE PROCEDURE CRC_TEST (f1 varchar2) AS
         RetValue varchar2(100);
    BEGIN
         if check_file_crc(f1) then
              RetValue := '0';
         else
              RetValue := '1';
         end if;
         DBMS_OUTPUT.PUT_LINE(RetValue);
    EXCEPTION
         when others then
         DBMS_OUTPUT.PUT_LINE(sqlerrm|| 'I am in exception');
    END;
    4.ET SERVEROUTPUT ON
    SQL> exec crc_test('C:\file.txt');
    ORA-28576: lost RPC connection to external procedure agent
    I am in exception
    I have tsnames.ora as
    EXTPROC_CONNECTION_DATA =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
    (CONNECT_DATA =
    (SID = PLSExtProc)
    (PRESENTATION = RO)
    and listner.ora as
    SID_LIST_LISTENER =
    (SID_LIST =
    (SID_DESC =
    (SID_NAME = PLSExtProc)
    (ORACLE_HOME = D:\Oracle\ora81)
    (PROGRAM = extproc)
    I am unable to resolve problem please help.
    Prashant
    Edited by: prashant13 on Jul 23, 2009 11:27 AM

    See if MOS note      468404.1 proves helpful here (though not meant for your version of Oracle).

  • How can I execute an external program from within a button's event handler?

    I am using Tomcat ApacheTomcat 6.0.16 with Netbeans 6.1 (with the latest JDK/J2EE)
    I need to execute external programs from an event handler for a button on a JSF page (the program is compiled, and extremely fast compared both to plain java and especially stored procedures written in SQL).
    I tried what I'd do in a standalone program (as shown in the appended code), but it didn't work. Instead I received text saying the program couldn't be found. This error message comes even if I try the Windows command "dir". I thought with 'dir' I'd at least get the contents of the current working directory. :-(
    I can probably get by with cgi on Apache's httpd server (or, I understand tomcat supports cgi, but I have yet to get that to work either), but whatever I do I need to be able to do it from within the button's event handler. And if I resort to cgi, I must be able to maintain session jumping from one server to the other and back.
    So, then, how can I do this?
    Thanks
    Ted
    NB: The programs that I need to run do NOT take input from the user. Rather, my code in the web application processes user selections from selection controls, and a couple field controls, sanitizes the inoputs and places clean, safe data in a MySQL database, and then the external program I need to run gets safe data from the database, does some heavy duty number crunching, and puts the output data into the database. They are well insulated from mischeif.
    NB: In the following array_function_test.pl was placed in the same folder as the web application's jsp pages, (and I'd tried WEB-INF - with the same result), and I DID see the file in the application's war file.
            try {
                java.lang.ProcessBuilder pn = new java.lang.ProcessBuilder("array_function_test.pl");
                //pn.directory(new java.io.File("K:\\work"));
                java.lang.Process pr = pn.start();
                java.io.BufferedInputStream bis = (java.io.BufferedInputStream)pr.getInputStream();
                String tmp = new String("");
                byte b[] = new byte[1000];
                int i = 0;
                while (i != -1) {
                    bis.read(b);
                    tmp += new String(b);
                getSelectionsDisplayTextArea().setText(getSelectionsDisplayTextArea().getText() + "\n\n" + tmp);
            } catch (java.io.IOException ex) {
                getSelectionsDisplayTextArea().setText(getSelectionsDisplayTextArea().getText() + "\n\n" + ex.getMessage());
            }

    Hi Fonsi!
    One way to execute an external program is to use the System Exec.vi. You find it in the functions pallet under Communication.
    /Thomas

  • How can I run an external program from a PLSQL procedure?

    Is there a package to run an external program from PLSQL? or is there another way to do that?
    thanks.

    here there is an example about how a PL/SQL procedure can
    work with an external C program.
    http://download-east.oracle.com/docs/cd/A87860_01/doc/appdev.817/a76936/dbms_pi2.htm#1003384
    Apart from that you have Java Stored Procedures option
    to carry out your task.
    Java Stored Procedures Developer's Guide Contents / Search / Index / PDF
    http://download-east.oracle.com/docs/cd/B10501_01/java.920/a96659.pdf
    Joel P�rez

  • How to call external programs?

    I have seen people call external programs through LabVIEW and was curious what functions you could use to do this.
    I'm pretty sure its using one of the ActiveX functions  or maybe 'open application reference .vi'.
    Can anyone tell me (or show me) a quick example of how to open an external program (ie excel,  notepad, etc) programatically
    Cory K
    Solved!
    Go to Solution.

    Cory K wrote:
    Where did they get this:
    Kudos for going from "I don't know to start" to "Let's stump Ben" with only the second post to this thread.
    I either copy it from an example or try to browse to it.
    NOTE:
    If you plan to work with MS ActiveX objects, I found it very helpful to do a custom install of Office and make sure the help files for VBA are loaded. These will at the least give you an idea of what the methods are and what parameters go with each.
    Ben
    Message Edited by Ben on 12-31-2008 11:09 AM
    Message Edited by Ben on 12-31-2008 11:13 AM
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction
    Attachments:
    Browse.PNG ‏24 KB

Maybe you are looking for