Host command in PL/SQL Package

Hi,
How is it possible to launch a host command from a PL/SQL package without Pro*C nor Java ?
Hope it's possible, 'cos Java is not available here and Pro*C has some^problems that the DBA cqn't solve...
Could you please answer at [email protected]
Thanks in advance !

Hi Thomas,
You can call external progs within PlSql.
You have to
- Configure Tnsnames.ora aned listener.ora on the server
with the 'extproc' entry
- Have an external proc in a DDL on NT (or .so on unix)
- Create a libray pointing on this .so file with 'Create library'
- Declare a PlSql proc calling your external proc in the library
And then you will use your PlSql proc within your package.
It's fastidious but it works.
Mbo

Similar Messages

  • A HOST command in PL/SQL?

    Hello guys! :)
    I need to execute some SFTP commands on the database server to another SFTP server. In oracle forms theres a built in called "HOST" which executes native commands on the server. Is there something similar to that in PL/SQL?
    Also, im wondering of each call of the "HOST" command opens a new session in CMD. I'll need to log in, submit files, and retrieve files as well. If the HOST command opens a new session everytime, ill lose the login credentials from the first HOST command.
    Anyone know of anything like this thats been done before? Let me know. Thanks.
    Mo

    Duplicate thread
    SFTP in PL/SQL
    Please do not repost if the prior answers don't suit you.
    The answer to your question is obviously there is no HOST command in PL/SQL, as there has never been a HOST command, as Oracle happens to be a RDBMS.
    You could use the external procedure facility, you could also call Java.
    Tom Kyte has an utility for this on http://asktom.oracle.com, called run_cmd
    Sybrand Bakker
    Senior Oracle DBA

  • Host Command from PL/SQL

    Hi,
    We use JAVA source in Oracle to execute some unix commands directly from within stored procedures in Oracle.
    Our Java source looks like this :
    CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "HOST" AS
    import java.lang.*;
    import java.io.*;
    public class Host
    public static void executeCommand (String command, String etype) throws IOException
    String[] wFullCommand = {"C:\\winnt\\system32\\cmd.exe", "/y", "/c", command};
    String[] uFullCommand = {"/bin/sh", "-c", command};
    if (etype.toUpperCase().equals("W"))
    Runtime.getRuntime().exec(wFullCommand);
    else if(etype.toUpperCase().equals("U+"))
    Runtime.getRuntime().exec(uFullCommand);
    else if(etype.toUpperCase().equals("U"))
    Runtime.getRuntime().exec(command);
    CREATE OR REPLACE PROCEDURE Host_Command (p_command IN VARCHAR2, p_etype IN VARCHAR2)
    AS LANGUAGE JAVA
    NAME 'Host.executeCommand (java.lang.String, java.lang.String)';
    We call one unix shell script and discover that some UNIX commands from this shell script are executed and others not. A cp & touch command don't give problems whilst cat & unix2dos commands don't function.
    Can anybody help me on this subject?
    Thanks !
    Kris

    Thanks for your reactions. Got it to work with the unix scripts, the problem was a syntax error in the script itself.
    However I don't get it to function when I try to run a unix command directly. Normally the parameter U+ should decide to start it in a shell for scripts and otherwise it should run the command directly. (whithout the /bin/sh in front of it).
    I already adapted my source to try to execute the command in a new shell but without success :
    String[] uFullCommand = {"/bin/sh", "-c", "\'cp /export/home/caluwaek/test/bestand2 /export/home/caluwaek/test/bestand8\'"};
    I tried to put the whole command in one string, in 3 strings, to just call the cp command without bothering the shell. Nothing seems to work.
    In unix both the following work :
    cp /export/home/caluwaek/test/bestand2 /export/home/caluwaek/test/bestand8
    and
    /bin/sh -c 'cp /export/home/caluwaek/test/bestand2 /export/home/caluwaek/test/bestand8'
    Thanks for your help!
    Kris

  • Host command

    can i user host command in pl-sql. if so then tell me how i can.

    Hi, you can't run a host command
    directly from pl/sql.
    Look at
    http://technet.oracle.com:89/ubb/Forum88/HTML/001295.html
    for a short description, how it can be done.
    HTH
    Detlev

  • HOST command and Forms 4.5

    We were using HOST command(to start SQL Plus) in one of the form of our application (forms version 4.5) and this application was running fine on Win NT. Now this application is moved onto Windows 2000. Now we noticed that once the HOST command statement is executed, the application goes into hang and has to terminated. We fixed this problem temporarily by putting a message() and pause statement before and after HOST command statement and the application is running fine. I would like a better solution to this problem. If anyone has encountered this kind of problem or any idea, please reply.

    Hi, there,
    I have the same problem with my program. Have you figured it out the solution? and if not, could you show me the code of your temporary fix? my email is: [email protected]
    Thanks
    We were using HOST command(to start SQL Plus) in one of the form of our application (forms version 4.5) and this application was running fine on Win NT. Now this application is moved onto Windows 2000. Now we noticed that once the HOST command statement is executed, the application goes into hang and has to terminated. We fixed this problem temporarily by putting a message() and pause statement before and after HOST command statement and the application is running fine. I would like a better solution to this problem. If anyone has encountered this kind of problem or any idea, please reply.

  • Running sqlldr command from PL/SQL Block

    DECLARE
    BEGIN
    END;

    In SQL * plus we can run DOS commands using the following command
    HOST DIR
    HOST DIR/P
    But When we can't run the HOST command in PL/SQL Block..
    I have to Run sqlldr command from PL/SQL Block..
    i tried as follows
    DECLARE
    BEGIN
    EXECUTE IMMEDIATE ' host sqlldr control= bad= ';
    END;
    By
    BalaNagaRaju

  • Calling SQL Loader using HOST command from Developer Forms 4.5

    I want to execute a set of code from D2K Forms 4.5 which has interfface with Client - OS ( In my case Windows NT/XP). I want to execute SQL Loader from Forms using Host Command and then after completion of that process, I want to do next transcations ( depending upond success of HOST/SQL Loader).
    How to achive this?
    I tried writing code like this ...
    l_vc_command := 'sqlldr73'
                        ||' USERID='||l_vc_username||'/'||l_vc_password||'@'||l_vc_connect_string
                        ||' CONTROL='||l_vc_filepath||'Upload.ctl'
                        ||' DATA='||LTRIM(RTRIM(l_vc_fileloc))
                        ||' LOG='||l_vc_filepath|| l_vc_log_file || '_' || l_dt_sysdate_str ||'.log'                    
                        ||' BAD='||l_vc_filepath|| l_vc_bad_file || '_' || l_dt_sysdate_str ||'.bad'
                        ||' DISCARD='||l_vc_filepath|| l_vc_discard_file || '_' || l_dt_sysdate_str ||'.dsc';
    HOST(l_vc_command,NO_PROMPT);
    After this command i want to do some other code execution. so even if it fails or success, next code is executed. How to control this?
    Please help..
    Regards,
    Milind

    Forms6i running on W2000, Rdbms 8.1.7
    in Forms I added a button TEST,
    Trigger when-button-pressed : host('test.bat') ;
    in directory .......\frm I added file test.bat :
    REM ===============
    cd /d C:\........\ldr
    pause
    sqlldr parfile=test.par
    pause
    type test.log
    pause
    exit
    REM ================
    now, pressing TEST button opens DOS window, telling me what's going on, running sqlldr, finally going back to forms
    Are you using NO_PROMPT or NO_SCREEN option of HOST command ?
    Had a look at Forms 4.5 manuals, there is no mentioning of (a)synchronously operation in connection with HOST command.

  • Calling SQL Loader from Forms 4.5 using HOST command in Win2000

    One of my forms calls SQL Loader 7.3 using HOST command to load a csv file onto the database(Oracle 7.3) under Windows 2000 platform.
    Only after sql loader finishes its operation the control should come to my form i.e. synchronous execution.
    As of now its running asynchronously.
    Is there any way to make it synchronous. If Not any other work arounds?
    Environment Details
    Forms [32 Bit] Version 4.5.10.6.0 (Production)
    Windows 2000 Operating System
    Oracle7 Release 7.3.2.3.2

    Forms6i running on W2000, Rdbms 8.1.7
    in Forms I added a button TEST,
    Trigger when-button-pressed : host('test.bat') ;
    in directory .......\frm I added file test.bat :
    REM ===============
    cd /d C:\........\ldr
    pause
    sqlldr parfile=test.par
    pause
    type test.log
    pause
    exit
    REM ================
    now, pressing TEST button opens DOS window, telling me what's going on, running sqlldr, finally going back to forms
    Are you using NO_PROMPT or NO_SCREEN option of HOST command ?
    Had a look at Forms 4.5 manuals, there is no mentioning of (a)synchronously operation in connection with HOST command.

  • Within SQL*Plus, get error code of host command

    Hello everyone,
    I am currently writing an SQL*Plus (Oracle 10g) that has a big logic and somewhere in the middle, I have to call a host command, which is an C++ function.
    I call it using
    SQL> HOST cd
    SQL> HOST cd bins
    SQL> HOST ./my_procedureBut, I need to get the return code of my procedure to see if it finished correctly?
    I checked [the manual|http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/ch4.htm#sthref883] but they don't say anything about return codes.
    When I try:
    SQL> host echo $?
    0It always returns 0, even if I SIGTERM or SIGKILL the child process. Anyone has an idea on how is it possible to retrieve the return code?
    Thanks

    user13117585 wrote:
    Hello guys and thanks for your answers.
    Let me tell you a little more about my problem... I have a 3 steps process. The first step is done in the database. It updates a few tables. Then, when that step successfully ends, I need to start a second step. That second step is done on the server where I have my SQL Plus session. Because I actually have 2 different machines. The first one is where the database is running and the second one where I have SQL Plus (Oracle client 10g) and the program that I have to start in this second step. Then, once this process is finished and his return code is 0, then I have to execute the third step in the database.
    Basically, I wanted to have something like:
    VARIABLE returnCode
    BEGIN
    :returnCode := some_package.do_step_1;
    -- do whatever I want with returnCode.
    EXCEPTION WHEN ...
    END;
    HOST execute_external_program
    BEGIN
    IF external_job_succeed THEN
    some_package.do_step_3
    END IF;
    EXCEPTION...
    END;
    /I wanted to use the Oracle Scheduler to create an EXTERNAL JOB. The problem is that the external program is not deployed on the same machine as the database.I know that on 11g, we have external remote jobs. But I'm on 10g and I have no agent on the server where the external program is. So, what are my options? SQL*Plus and the host command... Or I can also write a bash script to do that... Or any hight level programming language...
    Any other idea?
    Thanks again guys,move functionality of second step into PL/SQL procedure resident inside DB.

  • Java running host command - moved from PL/SQL forums

    Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
    PL/SQL Release 11.1.0.6.0 - Production
    CORE 11.1.0.6.0 Production
    TNS for HPUX: Version 11.1.0.6.0 - Production
    NLSRTL Version 11.1.0.6.0 - Production
    Hi,
    I am not familiar with Java setting in Oracle
    I have a a stored procedure that call a java program to execute host command like
    ssh user1@localhost '/home/user1/someprogram'
    if we execute this directly using PuTTY
    we can do the following with no problem
    su - oracle
    ssh user1@localhost '/home/user1/someprogram'
    but when we execute the stored procedure,
    we have to do
    */usr/bin/ssh* user1@localhost '/home/user1/someprogram'
    does anybody where to set the path or environment to make the java know the path correctly.
    thanks
    ps:. this is happen after we recently upgraded our Oracle from 9.2.0.8 to 11.1.0.6

    pgoel wrote:
    You said,
    a stored procedure that call a java program to execute host command like ssh user1@localhost '/home/user1/someprogram'SP -calls> Java Program (JP) -runs> ssh user1@localhost '/home/user1/someprogram'. is that right? I presume locahost is a database server.correct
    this is the stored procedure
    CREATE OR REPLACE PROCEDURE host_command (p_command  IN  VARCHAR2)
      AS LANGUAGE JAVA
      NAME 'Host.executeCommand (java.lang.String)';and this is the java
    create or replace and compile java source named host as
    import java.io.*;
    public class Host {
      public static void executeCommand(String command) {
        try {
          String[] finalCommand;
          if (isWindows()) {
            finalCommand = new String[4];
            // Use the appropriate path for your windows version.
            finalCommand[0] = "C:\\windows\\system32\\cmd.exe";  // Windows XP/2003
            //finalCommand[0] = "C:\\winnt\\system32\\cmd.exe";  // Windows NT/2000
            finalCommand[1] = "/y";
            finalCommand[2] = "/c";
            finalCommand[3] = command;
          else {
            finalCommand = new String[3];
            finalCommand[0] = "/bin/sh";
            finalCommand[1] = "-c";
            finalCommand[2] = command;
          final Process pr = Runtime.getRuntime().exec(finalCommand);
          pr.waitFor();
          new Thread(new Runnable(){
            public void run() {
              BufferedReader br_in = null;
              try {
                br_in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
                String buff = null;
                while ((buff = br_in.readLine()) != null) {
                  System.out.println("Process out :" + buff);
                  try {Thread.sleep(100); } catch(Exception e) {}
                br_in.close();
              catch (IOException ioe) {
                System.out.println("Exception caught printing process output.");
                ioe.printStackTrace();
              finally {
                try {
                  br_in.close();
                } catch (Exception ex) {}
          }).start();
          new Thread(new Runnable(){
            public void run() {
              BufferedReader br_err = null;
              try {
                br_err = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
                String buff = null;
                while ((buff = br_err.readLine()) != null) {
                  System.out.println("Process err :" + buff);
                  try {Thread.sleep(100); } catch(Exception e) {}
                br_err.close();
              catch (IOException ioe) {
                System.out.println("Exception caught printing process error.");
                ioe.printStackTrace();
              finally {
                try {
                  br_err.close();
                } catch (Exception ex) {}
          }).start();
        catch (Exception ex) {
          System.out.println(ex.getLocalizedMessage());
      public static boolean isWindows() {
        if (System.getProperty("os.name").toLowerCase().indexOf("windows") != -1)
          return true;
        else
          return false;
    Where does Java Progarm reside? On the database server filesystem OR within the Database itslef. within the Database itslef.
    Edited by: HGDBA on Mar 11, 2011 1:50 PM

  • Can PL/SQL Run Host Command (DOS Command) ??

    Hi All,
    Can PL/Sql run HOST Command ?
    If can't, iis there any other way to execute the DOS command ?
    Thanks for help.
    Iwan

    Hi sarah,
    i have tried, but it didn't work.
    in my abc.sql script : (host in pl/sql level)
    BEGIN
    HOST('cmd /C dir *.*');
    END;
    exit
    but it still didn't work
    so i tried in sqlplus level :
    variable vStatus VARCHAR2(1);
    variable vCmd VARCHAR2(3000);
    BEGIN
    :vCmd := 'C:\Program Files\Internet Explorer\iexplore';
    END;
    HOST("C:\Program Files\Internet Explorer\iexplore");
    EXIT;
    if i put HOST("C:\Program Files\Internet Explorer\iexplore"); --> it worked....
    If i put HOST(:vCmd); --> i won't work.
    Any body can help ?
    Thanks,
    Iwan

  • Runnings Shell Commands in PL/SQL Procedure

    Hi folks,
    I want to run the SQL/Plus HOST command within an PL/SQL Procedure.
    I tried it with "EXECUTE IMMEDIATE 'HOST ls -la';"
    and I'm afraid, that it didn't work.
    Has anyone of you a suggestion?
    regards
    Markus

    you can use system library.
    Example for UNIX:
    <<< create library in DB >>>
    SQL>create or replace library libc
    as
    '/lib/libc.so';
    <<< create procedure >>>
    SQL>create or replace function libc_system (
    cmd_str in varchar2
    ) return pls_integer
    as external
    library libc
    name "system"
    language c
    parameters (cmd_str string);
    <<< use it! >>>
    SQL>exec libc_system('/usr/bin/cp /home/myhome/thefile /export/myfiles/thefile1);
    NOTE1: You are need to be a familiar with "extproc" feature...
    NOTE2: sometime(or always) you are need to put full path to executable files, like: "/usr/bin/cp"
    I didn't checked a usage of env variables, like: $HOME, $ORACLE_HOME, etc...
    NOTE3: This way can't be used to return a "screen" info from the function, like: "cat file1.txt | grep SOMETHING ".
    For this case you can use utl_file package, like: "cat file1.txt | grep SOMETHING > file2". After that you can use utl_file package to read file2...
    null

  • Run OS command from Pl/SQL

    Is there any way to execute an OS command from pl/sql other than using dbms_pipe & pro*C combo. I have done this way before but it seems there is built-in oracle package which can do this in 8/8i.
    Also HOST command in forms will execute the OS coomand from the clinet. Is there any way to execute the OS command on the server from the forms clinet?
    thanks,
    Ravi.
    null

    Ravi,
    Can you send me an example how one can
    execute a this command from a PL/SQL
    program 'sed 3q /etc/passwd'.
    Please write to me at
    [email protected]
    thanks
    Pramod

  • PL/SQL package SYS.DBMS_BACKUP_RESTORE version 11.02.00.01 in AUXILIARY dat

    Hi,
    My primary and stand by db are 11.2.0.3
    from my primary db host , when i executed the below commands , it errors out . Can you please adive the fix
    RMAN> connect target sys/sys@chicago;
    connected to target database:chicago (DBID=4194693498)
    RMAN> connect auxiliary sys/sys@austin;
    **PL/SQL package SYS.DBMS_BACKUP_RESTORE version 11.02.00.01 in AUXILIARY database is not current**
    **PL/SQL package SYS.DBMS_RCVMAN version 11.02.00.01 in AUXILIARY database is not current**
    **connected to auxiliary database: austin (DBID=4194693498)**
    Can you please advice how to over come it
    Thanks
    [email protected]
    Edited by: user12096071 on Feb 14, 2012 6:59 PM

    Hi ,
    I am trying to build the active dataguard using the below 3 commands. Both my primary and stand by are at 11.2.0.3 . I deleted all the datafile on stand by.
    I issued below command from my primary database
    RMAN> connect target sys/xxxxx@chicago ( executed successfully )
    RMAN> connect auxiliary sys/xxxxx@austin ( got below error )
    **PL/SQL package SYS.DBMS_BACKUP_RESTORE version 11.02.00.01 in AUXILIARY database is not current**
    **PL/SQL package SYS.DBMS_RCVMAN version 11.02.00.01 in AUXILIARY database is not current**
    **connected to auxiliary database: austin (DBID=4194693498)**
    RMAN> run{duplicate target database for standby from active database;} ( yet to execute this command).
    Do i need to execute above command from stand by host?
    thanks
    Naveen

  • Trouble Running Host Command

    Hello folks I am trying to create a procedure to run linux host commands. I have found and used code available throughout the internet and it compiles and runs, but no matter what command I send to the host I get a 'Not Found' exception, even if I send as the command the full path to the executable. Here is my code:
    *1- Java Procedure*
    CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Host" AS
    import java.io.*;
    public class Host {
    public static void executeCommand(String command) {
    try {
    String[] finalCommand;
    if (System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) {
    finalCommand = new String[4];
    finalCommand[0] = "C:\\winnt\\system32\\cmd.exe";
    finalCommand[1] = "/y";
    finalCommand[2] = "/c";
    finalCommand[3] = command;
    } else {                              // Linux or Unix System
    finalCommand = new String[3];
    //finalCommand[0] = "/bin/sh";
    //finalCommand[1] = "-c";
    //finalCommand[2] = "'" + command + "'";
    finalCommand[0] = command;
    finalCommand[1] = "";
    finalCommand[2] = "";
    // Execute the command...
    final Process pr = Runtime.getRuntime().exec(finalCommand);
    // Capture output from STDOUT...
    BufferedReader br_in = null;
    try {
    br_in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
    String buff = null;
    while ((buff = br_in.readLine()) != null) {
    System.out.println("stdout: " + buff);
    try {Thread.sleep(100); } catch(Exception e) {}
    br_in.close();
    } catch (IOException ioe) {
    System.out.println("Error printing process output.");
    ioe.printStackTrace();
    } finally {
    try {
    br_in.close();
    } catch (Exception ex) {}
    // Capture output from STDERR...
    BufferedReader br_err = null;
    try {
    br_err = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
    String buff = null;
    while ((buff = br_err.readLine()) != null) {
    System.out.println("stderr: " + buff);
    try {Thread.sleep(100); } catch(Exception e) {}
    br_err.close();
    } catch (IOException ioe) {
    System.out.println("Error printing execution errors.");
    ioe.printStackTrace();
    } finally {
    try {
    br_err.close();
    } catch (Exception ex) {}
    catch (Exception ex) {
    System.out.println("Exception: " + ex.getLocalizedMessage());
         ex.printStackTrace();
    *2- PL/SQL Package*
    CREATE OR REPLACE PACKAGE CIF_HOST_PKG IS
    PROCEDURE host (p_command IN VARCHAR2);
    END CIF_HOST_PKG;
    PROCEDURE host (p_command IN VARCHAR2)
    AS LANGUAGE JAVA
    NAME 'Host.executeCommand (java.lang.String)';
    END CIF_HOST_PKG;
    *3- Java Permission*
    EXEC Dbms_Java.Grant_Permission('CIF', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
    EXEC Dbms_Java.Grant_Permission('CIF', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');
    exec dbms_java.grant_permission( 'CIF', 'SYS:java.io.FilePermission', '/bin/sh', 'execute' );
    exec dbms_java.grant_permission( 'CIF', 'SYS:java.io.FilePermission', '/bin/ps', 'read , execute' );
    exec dbms_java.grant_permission( 'CIF', 'SYS:java.io.FilePermission', '/bin/ls', 'read , execute' );
    *4- Test Code*
    set serveroutput on size 1000000
    exec dbms_java.set_output(1000000)
    exec CIF_HOST_PKG.host('/bin/ls -l');
    *5- Test Output*
    anonymous block completed
    Exception: Exception during creation of the process: java.io.IOException: '/bin/ls -l' not found
    java.io.IOException: Exception during creation of the process: java.io.IOException: '/bin/ls -l' not found
         at java.lang.OracleProcess.start(OracleProcess.java:259)
         at java.lang.ProcessBuilder.start(ProcessBuilder.java:483)
         at java.lang.Runtime.exec(Runtime.java:591)
         at java.lang.Runtime.exec(Runtime.java:464)
         at Host.executeCommand(Host:24)
    Any idea on what am I doing wrong?
    Thank you in advance,
    Andre

    Has oracle user permissions to /bin/ls ?
    try in sqlplus:
    host /bin/ls -lIf not try chmod 777 /bin/lsElse you can try my package http://github.com/xtender/xt_svn
    select * from table(XT_SVN_TEST.shell_exec('/bin/ls -l /var/tmp'))Best regards,
    Malakshinov Sayan

Maybe you are looking for

  • Preview app: Add text annotation with left justify?

    I'm using the Preview app to insert text into some PDF files. I can use the Annotate feature to create a text box in the area I need it and adjust the font, color, size, etc. The only thing I can't seem to do is set the justification to Left Justify.

  • Photoshop Elements won't start, closes, says no serial #

    I had to get a new computer, mother board died. Old hard drive installed as d drive and all programs work fine except Photoshop Elements. looks like it will start, asks me to agree to user agreement, I click agree and it says I did not and will shut

  • Can I connect my TV to my Apple TV3 via bluetooth?

    Trying to minimize the wires and was wondering if I can avoid having to connect the ATV directly to the TV. To be honest, I dont even know if its possible to transmit video via BT?

  • Quick Time Movies Trapped In iPhoto 09?

    Hi: I download quicktime move clips from my panasonic camera and they automatically are saved (along with still photos) in iPhoto. In the past I have been able to just click on them to play and to move them freely into other files. Now with IPhoto 09

  • HT201272 how to cancel download of movie

    My son purchased a movie and it will take 3 hours to download into his iPod! It is preventing other downloads and we would like to know if gthere is a way to not have to download the movie and just cancel it!