Logo Background
  • Invoking SQL Loader HostCommand Using PL/SQL
    By guru on January 26, 2010 | No Comments  Comments

    Is there any way to invoke or execute Unix command from Oracle PL/SQL? Hostcommand will be the answer where it is another alternative way for Unix call and we don’t need to write any shell script to achieve the execution.

    Hostcommand is a function or utility in Oracle database which was used to pass in command to Unix operating system for execution.

    We mentioned that we can call the hostcommand in either SQL or PL/SQL in our previous post of HostCommand Unix Call From Oracle SQL.

    The example below shows on how we call the sqlldr binary from Unix database machine using hostcommand feature in PL/SQL.

    The reason of why we are calling the sqlldr from Unix machine was the version of 10.x can be used to load the XML data file into database.

    CREATE OR REPLACE PROCEDURE APPS.ORACLE_XML_SQLLDR
    (errbuf  out varchar2, retcode out number) IS
    l_err_msg varchar2(80);
    l_err_code number;
     
    i number;
     
     
    begin
     
    fnd_file.put_line(fnd_file.log,'Launch sqlldr from Unix database machine');
    fnd_file.put_line(fnd_file.log,'sqlldr_runtime = '||
    hostcommand('/oracle/product/bin/sqlldr apps/<password> 
    control=<.ctl location> log=<.log location>')); 
    fnd_file.put_line(fnd_file.log,'Finish sqlldr');
     
     
    end;
    /