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

Similar Messages

  • 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

  • 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

  • Copy Command in Pl/Sql block

    Can I use Copy command in Pl/Sql.For example :-
    Declare
    cursor c1 is select table_name from all_tables
    where owner = 'LSP' and rownum = 1;
    v1 varchar2(2000);
    Begin
    for c2 in c1 loop
    v1:='copy from lsp/lsp123479@dvlaq to scott/[email protected] create '|| c2.table_name ||' using select * from '||c2.table_name;
    execute immediate v1;
    end loop;
    end;
    Its not running properly giving an error as invalid Sql statement .
    Is it bcoz Copy command cannot be used in a Pl/Sql Block.

    Is there any other way to move the Table & data to another Data Base .Database link is the obvious one. And the SQL statement would look something like this (on the target database):
    SQL> create table FOO nologging as select * from FOO@sourcedb;
    However, the first question I always ask if why? What one may think is the solution to a problem is not always the best solution. So one need to identify the problem first, and then see what solutions there are and which one is the best fit.
    Other options are replication (using materialised views for example), Data Pump (available with 10G) - even could be Data Guard, a standby database, or a Real Application Cluster... depending on just what the problem and actual requirements are.
    Also important to note that SQL*Plus has its own set of commands. Do not confuse these commands (like EXEC, COPY, CONNECT, HOST etc) with the SQL and PL/SQL Languages. Not only are they executed by different software products, SQL*Plus commands are executed on the client and SQL (and PL/SQL) runs inside the Oracle database instance.

  • How to execute host command in trigger

    dear professional:
    i'm trying to create a trigger that when a certain value inserts into a table , it fires some UNIX command to do the job following
    here is what i tried ,create a trigger that gives host command , but when i tried insert , it fails to work
    i also tried dbms_pipe ,but seems same when using dynamic sql to do the job
    any idea of how to accomplish this task ?
    many thanks ~
    br/ricky
    SQL> CREATE OR REPLACE TRIGGER price_exec
    2 BEFORE INSERT ON omc.price_test
    FOR EACH ROW
    BEGIN
    IF :NEW.price = 4 THEN
    execute immediate 'host ll';
    END IF;
    END price_exec;
    / 3 4 5 6 7 8 9
    Trigger created.
    SQL> insert into price values ('test',4);
    insert into price values ('test',4)
    ERROR at line 1:
    ORA-00942: table or view does not exist
    SQL> insert into price_test values ('test',4);
    insert into price_test values ('test',4)
    ERROR at line 1:
    ORA-00900: invalid SQL statement
    ORA-06512: at "OMC.PRICE_EXEC", line 3
    ORA-04088: error during execution of trigger 'OMC.PRICE_EXEC'

    hi,
    my db is 9.2
    i'm aware of schedule you mentioned , but if it's up to the task , you don't know when a row with certain value is inserted
    simple way :
    when a row inserted into a table with value "catch me" you want to know who inserted this test value
    so you tried to create a trigger to catch program, machine, module ,and terminal info from v$session
    so you can figure out where it is coming from
    and i want to go a step further , by executing some os command to digging out more
    and i come up with this , when value 4 is inserted i exec a procedure host to execute command,
    the problem is it's not working as i exepcted , so spare me the lecture of reading docs and just tell me what to do
    i'd really appreciate it , thanks
    CREATE OR REPLACE TRIGGER price_exec
    BEFORE INSERT ON omc.price_test
    FOR EACH ROW
    BEGIN
    IF :NEW.price = 4 THEN
    execute immediate 'host('echo')';
    END IF;
    END;
    Warning: Trigger created with compilation errors.
    SQL> show errors
    Errors for TRIGGER PRICE_EXEC:
    LINE/COL ERROR
    3/30 PLS-00103: Encountered the symbol "ECHO" when expecting one of
    the following:
    . ( * @ % & = - + ; < / > at in is mod not rem return
    returning <an exponent (**)> <> or != or ~= >= <= <> and or
    like between into using || bulk
    The symbol ". was inserted before "ECHO" to continue.

  • Webutil_file_transfer and host command doesn't work

    I use a host command in forms to execute a sql-script, which creates a file on AS. After the host command I use webutil_file_transfer to ftp the created file to the client. If I try to do this again in the same session, the host command fails. I have to restart the application to get it working again. If I leave out the webutil_file_transfer I have no problems whatsoever. It looks like webutil is changing something perhaps in the environment. Anyone has the same problem (and a suitable solution)?

    I can remove the files on AS (so there seems to be no lock). After removal of the files, no new files wil be created, even if I change the name of the file that needs to be created. Only restarting the application helps.
    Raoul

Maybe you are looking for

  • How do I access server with VPN?

    I have a connection via VPN to my work from home now. I'm on a MBP 10.6 and work is Cisco IPSec. It show the connection in my menu bar. My question is how do I now see my work files? I figured the vpn connection would show in my sidebar or on my desk

  • Deskjet 3050 J610a - Unexpected wireless connection problem.

    Running: MacOSX 10.7.4 HP Software: HP_Lion_Ink_SW_v12.13.17 Printer: Deskjet 3050 J610a had been working perfectly through wireless connection from a MacBook5,1 Intel Core 2 Duo, while I had been using HP Software HP_Installer_DJF4100_v9.7.1, that w

  • System is 8.1 64-bit.  iTunes is 32-bit.  Why?

    My computer is running Windows 8.1, 64-bit.  iTunes is 32-bit.  Why did 64-bit iTunes not install?

  • [URGENT]JMS Stuck at   connectionFactory.createQueueConnection();

    I am developing an OSB project and it has to insert a message on a OC4J Queue. I've been testing on *10.1.3.3.0* version and it workd fine. But the real version used is *10.1.3.0.0* and I don't know why but the request just gets stuck.... nothing hap

  • Book is Backwards in ibooks.

    I just opened a book in ibooks and it is backwards.  Where it normally would start is the end and where the end would be is the start.  It was liked it was scanned in reverse.  Is there a way to flip it around so I don't have to read it backwards.