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

Similar Messages

  • Java running host command

    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
    Edited by: HGDBA on Mar 11, 2011 10:49 AM

    OK. You can try the following:
    Login as the Unix user (e.g. oracle) on the pre-upgrade environment and run the following command.
    echo $PATH
    Repeat the above in the post-upgrade environment and compare the two outputs. Generally, PATH will be set using an environment script called from .profile of the user or it could be directly defined in .profile.
    You can check this by examining the .profile after logging in as the OS user (e.g. oracle):
    vi ~/.profile #i.e check the .profile in the user's home directory.
    It's my best guess, as sometimes the PATH could be added later on (for. e.g by another script). Anyways, give it a try and tell what you find.

  • Is it possible to run host command from SAP environment? How do you run?

    Hi
    Is it possible to run host command from SAP environment? How do you run?
    Thank You

    Hello Subhash
    You will more details in the following thread:
    Re: How to define command for SXPG_COMMAND_EXECUTE
    Regards
      Uwe

  • 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

  • Possible to run host command ???

    Hi experts,
    Is it possible to run host command from SAP environment? How do you run? 
    Thanks,
    Logu

    check whether this helps
    DATA:os TYPE sxpgcolist-opsystem.
        DATA:host TYPE rfcdisplay-rfchost.
        DATA:commandname TYPE sxpgcolist-name.
        DATA:exec_protocol LIKE STANDARD TABLE OF btcxpm.
        os = sy-opsys.
        host = sy-host.
        commandname = 'ZDOWNLOAD'.  "SAP Command Name
        CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
          EXPORTING
            commandname     = commandname
            operatingsystem = os
            targetsystem    = host
            stdout          = 'X'
            stderr          = 'X'
            terminationwait = 'X'
          TABLES
            exec_protocol   = exec_protocol[].
        IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.

  • Wht is run host command.

    Is it possible to run host command from SAP environment? how do u run

    Hello Shilpa,
    Please check the prerequisites for calling external Programms where the Host calling is described in detail in this folllwog link.
    http://help.sap.com/saphelp_nw2004s/helpdata/en/c4/3a7fbb505211d189550000e829fbbd/content.htm
    Please award points for helkpful answers.
    Revert back for queries.
    Br,
    Sri

  • Not able to create Oracle External Procedure to Run Host Commands

    Trying to follow this article
    http://timarcher.com/node/9
    Its related to
    Oracle External Procedure to Run Host Commands
    steps
    1)mkdir –p /u01/app/usfapp/oracle_external_procs/oracle_host
    2)
    Author is suggesting to create a file
    but header file is missing in very first line... may be not sure..say it is <stdio.h>Create a file named oracle_host.c. The contents of this file will be:
    #include
    int RunCmd(char *cmd)
    return(system(cmd));
    4) Create the file named makefile. The contents of this file will be:
    oracle_host: oracle_host.o
    gcc -shared -o oracle_host.so oracle_host.o
    $ cat makefile
    oracle_host: oracle_host.o
         gcc -shared -o oracle_host.so oracle_host.o
    5)
    Now run the command make
    The output on my server looks like:
    [u01/app/usfapp/oracle_external_procs/oracle_host]
    banner@usfbannerte [TRNG] > make
    gcc -shared -o oracle_host.so oracle_host.o
    here I stuck .. Not able to run this step ]$ make
    gcc -shared -o oracle_host.so oracle_host.o
    /usr/bin/ld: oracle_host.o: relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
    oracle_host.o: could not read symbols: Bad value
    collect2: ld returned 1 exit status
    make: *** [oracle_host] Error 1
    Any one has any idea what went wrong
    Any other link related to this is most welcomed.
    Please suggest ...

    hi
    please update
    or
    provide any other link / document for
    Oracle External Procedure to Run Host Commands
    --using c
    Thanks in advance.

  • Is it possible to run host command in sap environment

    hi
    could any body tel me
    is it possible to run host command in sap environment
    then how..?

    yeah , by using FM
    EXECUTE_FUNCTION
    Regards
    Prabhu

  • Running fscript commands directly from Tool code

    Does any one know how to run fscript commands directly from Tool code.
    Better still how to run a script file containing fscript commands
    directly from Tool code
    regards,
    Manish shirke.
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>

    Try that :
    RunCommand('fscript < MyScript.fsc');
    Hope this help you,
    At 12:29 02/10/98 -0400, Shirke, Manish wrote:
    Does any one know how to run fscript commands directly from Tool code.
    Better still how to run a script file containing fscript commands
    directly from Tool code
    regards,
    Manish shirke.
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>
    Jean-Baptiste BRIAUD software engineer
    SEMA GROUP france
    16 rue barbes
    92120 montrouge
    mailto:[email protected]
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>

  • How java runs in command prompt and why java runs on it

    how java runs in command prompt and why java runs on it

    command prompt was used before the development of IDEs like RAD,eclipse etc.
    its still used for better understanding of the compilation and errors.
    type the java file and save the file(source file) in the bin folder of ur jdk environment with extension .java. the source file must be the one that has the main method declared.
    in the cmd prompt screen , set the path of bin folder.
    eg:C:/program files/jdk(some version)/bin/...
    for compilation,type:
    javac (source file_name).java and press enter
    for running the file:
    java source file_name

  • 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

  • Moving from MS SQL 7 to Oracle 8i

    We are thinking about moving one of our client/server applications from MS SQL 7.0 to Oracle 8i. We know that we will have to change some of the datatypes in the database. But will there have to be a major rewrite of the backend code (stored procedures, triggers, views, etc...)? Does Oracle 8i support SQL or just PL-SQL and JAVA?

    Thank you all, at the end, i have fixed the problem. It seems root cause of the problem is my regional settings.
    I have completed to transfer my Sql schema to Oracle with errors. Migration Wizard gives errors in the stage of creating relations. It is something like that,
    Failed to create foreign key: ORA-02298 Cannot validate - Parent keys cannot find
    I have also tried to migrate my sql data but when the wizard finishes running, a large amount of my data is also lost.
    Do you have any suggestions?
    Thank you.
    Aykut

  • About running host command

    Hi,
    Suppose that I need to run 'zip' in the mean time when running Java, what should I use for calling such host command from O/S?
    Thks & Bst Rgds,
    Huamin

    Runtime.exec()

  • How to run an external application from PL/SQL code?

    Hi,
    I want to call an application like "Notepad" from PL/SQL code in a Windows2000 server. Is there any way to do that?
    Thanks, best regards.
    Paulo.

    declare
    r varchar(4000);
    begin
    dbms_java.set_output(10000);
    system_util.runshell('sh /ora9/runBackup.sh', r);
    dbms_output.put_line(r);
    end;
    System_util package is
    CREATE OR REPLACE PACKAGE System_Util IS
    *System: Generic
    *Package Name: System_util
    *Description: This is an open source package which holds regular used
         * methods by developers and dba's.
    *Created by:         Rae Smith
    *Created Date:       27/06/2001
    *Notes: This ia an free open source package that holds no warranty and
    * therefore no-one connected to the development of this package
    * can be made reasponsible for any outcomes by it's use.
    MODIFICATION LOG**************************************************************
    *DETAILS                                    DATE          VERS          CHANGED BY
    *===============================================================================
    *Created                                 27-06-2001     1.0           Rae Smith
         /********************************* Public Methhods ***************************************/
         --- getDir returns the first directory value held in the init.ora file
         FUNCTION getDir RETURN VARCHAR2;
         --- getPrev.. returns the prevoise day from a gievn date
         FUNCTION getPrevSat(pDate IN DATE) RETURN DATE;
         FUNCTION getPrevSun(pDate IN DATE) RETURN DATE;
         FUNCTION getPrevMon(pDate IN DATE) RETURN DATE;
         FUNCTION getPrevTue(pDate IN DATE) RETURN DATE;
         FUNCTION getPrevWed(pDate IN DATE) RETURN DATE;
         FUNCTION getPrevThu(pDate IN DATE) RETURN DATE;
         FUNCTION getPrevFri(pDate IN DATE) RETURN DATE;
         --- isNumber returns TRUE or FALSE depending on a datatype passed
         FUNCTION isNumber(pnumber IN VARCHAR2) RETURN BOOLEAN;
         FUNCTION isNumber(pnumber IN NUMBER) RETURN BOOLEAN;
         FUNCTION isNumber(pnumber IN DATE) RETURN BOOLEAN;
         --- The writeFile allow you to write data to a file
         --- writeFile has 2 Versions
         --- v1 pass in the file name and the text to write to a file.
         --- v2 pass in the file name, dbms_sql.varhar2s object
         --- and the amount of rows to procces at a time
         --- This enables you to write to afile in batch mode
         PROCEDURE writeFile(pName IN VARCHAR2, pText IN VARCHAR2);
         PROCEDURE writeFile(pName IN VARCHAR2, pText IN DBMS_SQL.VARCHAR2S, pRows IN PLS_INTEGER);
         --- The appendFile methods allow you to append data to a file
    --- This also has the inteligents to create the file if ts does not exist.
         --- appendFile has 2 Versions
         --- v1 pass in the file name and the text to write to a file.
         --- v2 pass in the file name, dbms_sql.varhar2s object
         --- and the amount of rows to procces at a time
         --- This enables you to write to afile in batch mode
         PROCEDURE appendFile(pName IN VARCHAR2, pText IN DBMS_SQL.VARCHAR2S, pRows IN PLS_INTEGER);
         PROCEDURE appendFile(pName IN VARCHAR2, pText IN VARCHAR2);
         --- The clearFile clears the data from a file.
         PROCEDURE clearFile(pName IN VARCHAR2);
         --- checkSyntax is a quick syntax checker for sql statements the is a limit to
         --- the size used in the statement. If you have a error with
         --- a statement then pass in the statement watch as it displays
         --- the point where the error arose.
         PROCEDURE checkSyntax(pSql IN VARCHAR2);
         --- isEmpty this returns TRUE or FALSE
         FUNCTION isEmpty(pValue IN VARCHAR2) RETURN BOOLEAN;
         --- getTimeInMins returns the time in minutes for a specified date
         FUNCTION getTimeInMins (pDate IN DATE) RETURN NUMBER;
         --PROCEDURE get_time_in_mins (pDate IN DATE);
         --- incDate returns a specified date incremented by value
         FUNCTION incDate(pInc IN NUMBER DEFAULT .999999, pDate IN DATE DEFAULT SYSDATE) RETURN DATE;
         --- decDate returns a specified date decremented by value
         FUNCTION decDate(pInc IN NUMBER DEFAULT .999999, pDate IN DATE DEFAULT SYSDATE) RETURN DATE;
         --- getTime returns the time in milliseconds
         FUNCTION getTime RETURN NUMBER;
         --- daysDiff returns the amount of days between two values
         FUNCTION daysDiff(pHigh IN DATE, pLow IN DATE) RETURN NUMBER;
         --- difference returns the diffeence between two numbers always
         --- taking the lowest away from the highest
         FUNCTION difference(pAnum IN NUMBER,pBnum IN NUMBER)RETURN NUMBER;
         --- total returns the value of two numbers added together
         FUNCTION total(pAnum IN NUMBER, pBnum IN NUMBER)RETURN NUMBER;
         --- numberToWords returns the string for a number passed in
         FUNCTION numberToWords(pNumb IN NUMBER) RETURN VARCHAR2;
         --- runShell allows you to run operating commands from pl/sql
         --- Only available with 8i
         --- PROCEDURE runShell(pCmnd IN VARCHAR2, pErrMsg IN OUT VARCHAR2);
         /**************************** Public Vaiables *******************************/
         --- Public variable that holds the operating system directory
         --- that the can be written to from withing the database.
         vDir VARCHAR2(50);
    END;
    CREATE OR REPLACE PACKAGE BODY System_Util IS
         FUNCTION getDir RETURN VARCHAR2
         IS
         BEGIN
              RETURN vDir;
         EXCEPTION
              WHEN OTHERS THEN
                   dbms_output.put_line('ERROR...ERROR...System_Util.getDir');
                   RAISE;
         END getDir;
         /**** Private module to get the first directory for utl_file to use ****/
         PROCEDURE getDir
         IS
              CURSOR cDir(p1 IN VARCHAR2)
              IS
              SELECT DECODE(INSTR(value, ','), 0, value, SUBSTR(value, 1, INSTR(value, ',')-1)) dir
              FROM v$parameter
              WHERE name = p1;
         BEGIN
              FOR rDir IN cDir('utl_file_dir') LOOP
                   vDir := rDir.dir;
              END LOOP;
         EXCEPTION
              WHEN OTHERS THEN
                   dbms_output.put_line('ERROR...ERROR...System_Util.getDir');
                   RAISE;
         END getDir;
         FUNCTION getPrevDate(pDate IN DATE, pDay IN VARCHAR2) RETURN DATE
         IS
         BEGIN
              RETURN NEXT_DAY(pDate - 7, pDay);
         EXCEPTION
              WHEN OTHERS THEN
                   RAISE;
         END getPrevDate;
         FUNCTION getPrevSat(pDate IN DATE) RETURN DATE
         IS
         BEGIN
              RETURN getPrevDate(pDate, 'saturday');
         EXCEPTION
              WHEN OTHERS THEN
                   RAISE;
         END getPrevSat;
         FUNCTION getPrevSun(pDate IN DATE) RETURN DATE
         IS
         BEGIN
              RETURN getPrevDate(pDate, 'sunday');
         EXCEPTION
              WHEN OTHERS THEN
                   RAISE;
         END getPrevSun;
         FUNCTION getPrevMon(pDate IN DATE) RETURN DATE
         IS
         BEGIN
              RETURN getPrevDate(pDate, 'monday');
         EXCEPTION
              WHEN OTHERS THEN
                   RAISE;
         END getPrevMon;
         FUNCTION getPrevTue(pDate IN DATE) RETURN DATE
         IS
         BEGIN
              RETURN getPrevDate(pDate, 'tuesday');
         EXCEPTION
              WHEN OTHERS THEN
                   RAISE;
         END getPrevTue;
         FUNCTION getPrevWed(pDate IN DATE) RETURN DATE
         IS
         BEGIN
              RETURN getPrevDate(pDate, 'wednesday');
         EXCEPTION
              WHEN OTHERS THEN
                   RAISE;
         END getPrevWed;
         FUNCTION getPrevThu(pDate IN DATE) RETURN DATE
         IS
         BEGIN
              RETURN getPrevDate(pDate, 'thursday');
         EXCEPTION
              WHEN OTHERS THEN
                   RAISE;
         END getPrevThu;
         FUNCTION getPrevFri(pDate IN DATE) RETURN DATE
         IS
         BEGIN
              RETURN getPrevDate(pDate, 'friday');
         EXCEPTION
              WHEN OTHERS THEN
                   RAISE;
         END getPrevFri;
         FUNCTION isNumber(pNumber IN VARCHAR2) RETURN BOOLEAN
         IS
         BEGIN
              IF TO_NUMBER(pNumber)> 0 THEN
                   RETURN TRUE;
              ELSE
                   RETURN FALSE;
              END IF;
         EXCEPTION
              WHEN OTHERS THEN
                   RETURN FALSE;
         END isNumber;
         FUNCTION isNumber(pNumber IN NUMBER) RETURN BOOLEAN
         IS
         BEGIN
              IF TO_NUMBER(pNumber) > 0 THEN
                   RETURN TRUE;
              ELSE
                   RETURN FALSE;
              END IF;
         EXCEPTION
              WHEN OTHERS THEN
              RETURN FALSE;
         END isNumber;
         FUNCTION isNumber(pNumber IN DATE) RETURN BOOLEAN
         IS
         BEGIN
              IF TO_NUMBER(TO_CHAR(pNumber, 'YYYYMMDD')) > 0 THEN
                   RETURN TRUE;
              ELSE
                   RETURN FALSE;
              END IF;
         EXCEPTION
              WHEN OTHERS THEN
                   RETURN FALSE;
         END isNumber;
         PROCEDURE writeFile(pName IN VARCHAR2, pText IN VARCHAR2)
         IS
              vFtype utl_file.file_type;
         BEGIN
              vFtype := UTL_FILE.FOPEN(vDir, pName,'w');
              UTL_FILE.PUT_LINE(vFtype,pText);
              UTL_FILE.FCLOSE(vFtype);
         EXCEPTION
              WHEN OTHERS THEN
                   UTL_FILE.FCLOSE(vFtype);
                   RAISE;
         END writeFile;
         PROCEDURE writeFile(pName IN VARCHAR2, pText IN VARCHAR2, pFtyp IN OUT utl_file.file_type)
         IS
              vFtype utl_file.file_type;
         BEGIN
              vFtype := UTL_FILE.FOPEN(vDir, pName,'w');
              UTL_FILE.PUT_LINE(vFtype,pText);
              UTL_FILE.FCLOSE(vFtype);
         EXCEPTION
              WHEN OTHERS THEN
                   UTL_FILE.FCLOSE(vFtype);
                   RAISE;
         END writeFile;
         PROCEDURE writeFile(pName IN VARCHAR2, pText IN DBMS_SQL.VARCHAR2S, pRows IN PLS_INTEGER)
         IS
              vFtype utl_file.file_type;
              vText VARCHAR2(2000);
              vCnt BINARY_INTEGER;
              vRem BINARY_INTEGER;
              vRowcnt PLS_INTEGER := 0;
         BEGIN
              vRem := MOD(pText.COUNT, pRows);
              vFtype := UTL_FILE.FOPEN(vDir, pName, 'w');
              vCnt := pText.FIRST;
              LOOP
                   EXIT WHEN vCnt IS NULL;
              vRowcnt := vRowcnt + 1;
                   IF vCnt = pText.LAST THEN
                        vText := vText||pText(vCnt);
                        UTL_FILE.PUTF(vFtype,vText);
                        UTL_FILE.FFLUSH(vFtype);
                        vText := '';
                   ELSIF MOD(vCnt, pRows) = 0 THEN
                        vText := vText||pText(vCnt)||'\n';
                        UTL_FILE.PUTF(vFtype,vText);
                        UTL_FILE.FFLUSH(vFtype);
                        vText := '';
                   ELSIF vRowcnt = vRem THEN
                        vText := vText||pText(vCnt)||'\n';
                        UTL_FILE.PUTF(vFtype,vText);
                        UTL_FILE.FFLUSH(vFtype);
                   ELSE
                        vText := vText||pText(vCnt)||'\n';
                   END IF;
                   vCnt := pText.NEXT(vCnt);
              END LOOP;
              UTL_FILE.FCLOSE(vFtype);
         EXCEPTION
              WHEN OTHERS THEN
                   dbms_output.put_line('ERROR...ERROR...SYSTEM_UTIL.WRITE_FILE');
                   UTL_FILE.FCLOSE(vFtype);
                   RAISE;
         END writeFile;
         PROCEDURE appendFile(pName IN VARCHAR2, pText IN DBMS_SQL.VARCHAR2S, pRows IN PLS_INTEGER)
         IS
              vFtype utl_file.file_type;
              vText VARCHAR2(2000);
              vCnt BINARY_INTEGER;
              vRem BINARY_INTEGER;
              vMode VARCHAR2(2) := 'a';
              vRowcnt PLS_INTEGER := 0;
         BEGIN
              vRem := MOD(pText.COUNT, pRows);
              vFtype := UTL_FILE.FOPEN(vDir, pName, vMode);
              vCnt := pText.FIRST;
              LOOP
                   EXIT WHEN vCnt IS NULL;
                   vRowcnt := vRowcnt + 1;
                   IF vCnt = pText.LAST THEN
                        vText := vText||pText(vCnt);
                        UTL_FILE.PUTF(vFtype,vText);
                        UTL_FILE.FFLUSH(vFtype);
                        vText := '';
                   ELSIF MOD(vCnt, pRows) = 0 THEN
                        vText := vText||pText(vCnt)||'\n';
                        UTL_FILE.PUTF(vFtype,vText);
                        UTL_FILE.FFLUSH(vFtype);
                        vText := '';
                   ELSIF vRowcnt = vRem THEN
                        vText := vText||pText(vCnt)||'\n';
                        UTL_FILE.PUTF(vFtype,vText);
                        UTL_FILE.FFLUSH(vFtype);
                   ELSE
                        vText := vText||pText(vCnt)||'\n';
                   END IF;
                   vCnt := pText.NEXT(vCnt);
              END LOOP;
                   UTL_FILE.FCLOSE(vFtype);
         EXCEPTION
              WHEN UTL_FILE.INVALID_OPERATION THEN
                   IF vMode = 'a' THEN
                        writeFile(pName, pText, pRows);
                   ELSE
                        RAISE;
              END IF;
         WHEN OTHERS THEN
              dbms_output.put_line('ERROR...ERROR...SYSTEM_UTIL.APPENDFILE');
              UTL_FILE.FCLOSE(vFtype);
              RAISE;
         END appendFile;
         PROCEDURE appendFile(pName IN VARCHAR2, pText IN VARCHAR2)
         IS
              vFtype utl_file.file_type;
              vMode VARCHAR2(2) := 'a';
         BEGIN
              vFtype := UTL_FILE.FOPEN(vDir, pName, vMode);
              UTL_FILE.PUTF(vFtype, pText);
              UTL_FILE.FFLUSH(vFtype);
              UTL_FILE.FCLOSE(vFtype);
         EXCEPTION
         WHEN UTL_FILE.INVALID_OPERATION THEN
         IF vMode = 'a' THEN
              writeFile(pName, pText);
         ELSE
              RAISE;
         END IF;
         WHEN OTHERS THEN
              dbms_output.put_line('ERROR...ERROR...SYSTEM_UTIL.APPENDFILE');
              UTL_FILE.FCLOSE(vftype);
              RAISE;
         END appendFile;
         PROCEDURE clearFile(pName IN VARCHAR2)
         IS
              vFtype utl_file.file_type;
              vText VARCHAR2(2000);
              vCnt BINARY_INTEGER;
              vRem BINARY_INTEGER;
              vRowcnt PLS_INTEGER := 0;
         BEGIN
              vFtype := UTL_FILE.FOPEN(vDir, pName, 'w');
              UTL_FILE.PUTF(vFtype,'');
              UTL_FILE.FFLUSH(vFtype);
              UTL_FILE.FCLOSE(vFtype);
         EXCEPTION
         WHEN OTHERS THEN
         dbms_output.put_line('ERROR...ERROR...System_Util.CLEARFILE');
         UTL_FILE.FCLOSE(vFtype);
         RAISE;
         END clearFile;
         PROCEDURE checkSyntax(pSql IN VARCHAR2)
         IS
         sqlCur PLS_INTEGER := DBMS_SQL.OPEN_CURSOR;
         errPos PLS_INTEGER;
         sqlStmt VARCHAR2(2000);
         BEGIN
              sqlStmt := pSql;
              DBMS_SQL.PARSE(sqlCur, sqlStmt, DBMS_SQL.NATIVE);
         EXCEPTION
              WHEN OTHERS THEN
                   errPos := DBMS_SQL.LAST_ERROR_POSITION;
                   DBMS_OUTPUT.PUT_LINE(SQLERRM);
                   DBMS_OUTPUT.PUT_LINE(sqlStmt);
                   DBMS_OUTPUT.PUT_LINE(' ');
                   DBMS_OUTPUT.PUT_LINE(LPAD('^', errPos, '-'));
                   DBMS_SQL.CLOSE_CURSOR(sqlCur);
         END checkSyntax;
         FUNCTION isEmpty(pValue IN VARCHAR2) RETURN BOOLEAN
         IS
         BEGIN
              IF pValue IS NULL OR pValue = '' OR pValue = ' ' THEN
                   RETURN TRUE;
              ELSE
                   RETURN FALSE;
              END IF;
         END isEmpty;
         FUNCTION getTimeInMins (pDate IN DATE) RETURN NUMBER
         IS
              vHours NUMBER;
              vMins NUMBER;
              vRetval PLS_INTEGER;
         BEGIN
              vHours := TO_NUMBER(TO_CHAR(pDate,'HH24'));
              vMins := TO_NUMBER(TO_CHAR(pDate,'MI'));
              vRetval := ((60 * vHours) + vMins);
              RETURN vRetval;
         EXCEPTION
              WHEN OTHERS THEN
                   RAISE;
         END getTimeInMins;
         PROCEDURE getTimeInMins (pDate IN DATE)
         IS
              vHours NUMBER;
              vMins NUMBER;
              vRetval PLS_INTEGER;
         BEGIN
              vHours := TO_NUMBER(TO_CHAR(pDate,'HH24'));
              vMins := TO_NUMBER(TO_CHAR(pDate,'MI'));
              vRetval := ((60 * vHours) + vMins);
              DBMS_OUTPUT.PUT_LINE('The time IN minutes IS: '||vRetval);
         EXCEPTION
              WHEN OTHERS THEN
                   RAISE;
         END getTimeInMins;
         FUNCTION incDate(pInc IN NUMBER DEFAULT .999999, pDate IN DATE DEFAULT SYSDATE) RETURN DATE
         IS
         BEGIN
         RETURN (TO_DATE(TO_CHAR(pDate + pInc, 'DD/MM/YYYY HH24:MI:SS'), 'DD/MM/YYYY HH24:MI:SS'));
         EXCEPTION
              WHEN OTHERS THEN
                   RAISE;
         END incDate;
         FUNCTION decDate(pInc IN NUMBER DEFAULT .999999, pDate IN DATE DEFAULT SYSDATE) RETURN DATE
         IS
         BEGIN
         RETURN (TO_DATE(TO_CHAR(pDate - pInc, 'DD/MM/YYYY HH24:MI:SS'), 'DD/MM/YYYY HH24:MI:SS'));
         EXCEPTION
              WHEN OTHERS THEN
                   RAISE;
         END decDate;
         FUNCTION getTime RETURN NUMBER
         IS
         BEGIN
              RETURN dbms_utility.get_time;
         END getTime;
         FUNCTION daysDiff(pHigh IN DATE, pLow IN DATE) RETURN NUMBER
         IS
              vHighdate DATE;
              vLowdate DATE;
         BEGIN
         IF pHigh > pLow THEN
                   vHighdate := TO_DATE(TO_CHAR(pHigh, 'YYYYMMDD'), 'YYYYMMDD');
                   vLowdate := TO_DATE(TO_CHAR(pLow, 'YYYYMMDD'), 'YYYYMMDD');
         ELSIF pLow > pHigh THEN
                   vHighdate := TO_DATE(TO_CHAR(pLow, 'YYYYMMDD'), 'YYYYMMDD');
                   vLowdate := TO_DATE(TO_CHAR(pHigh, 'YYYYMMDD'), 'YYYYMMDD');
         END IF;
              RETURN (vHighdate - vLowdate);
         EXCEPTION
              WHEN OTHERS THEN
                   RAISE;
         END daysDiff;
         PROCEDURE dateCheck(pDateFrom IN OUT DATE, pDateTo IN OUT DATE)
         IS
              /* Declare the variable to hold the "from" date */
              vDateFrom DATE;
         BEGIN
              /* If either date_from or date_to is null then set to todays date **
              ** using the sysdate **
              ** today's DATE AND IN the correct format */
              pDateFrom := NVL(pDateFrom, SYSDATE);
              pDateTo := NVL(pDateTo, SYSDATE);
              /* Check that the from date is not greater than the to date if so **
              ** use the system_util.incDate to Increment the date by 1 day */
              IF (pDateFrom > pDateTo) THEN
              vDateFrom := pDateFrom;
              pDateTo := System_Util.incDate(1, vDateFrom);
              END IF;
         EXCEPTION
              WHEN OTHERS THEN
              RAISE;
         END;
         /* calculates the difference of two numbers always taken the high from the low*/
         FUNCTION difference(pAnum IN NUMBER, pBnum IN NUMBER)RETURN NUMBER
         IS
              vTotal NUMBER;
         BEGIN
              IF (pAnum > pBnum )OR (pAnum = pBnum)THEN
                   vTotal := (pAnum - pBnum);
              ELSIF (pAnum < pBnum) THEN
                   vTotal := (pBnum - pAnum);
              END IF;
              RETURN (vTotal);
         EXCEPTION
              WHEN OTHERS THEN
                   RAISE;
         END difference;
         /* calculates the Total of two numbers*/
         FUNCTION total(pAnum IN NUMBER, pBnum IN NUMBER)RETURN NUMBER
         IS
              vTotal NUMBER;
         BEGIN
              vTotal := (pAnum + pBnum);
         RETURN (vTotal);
         EXCEPTION
              WHEN OTHERS THEN
                   RAISE;
         END total;
         FUNCTION numberToWords(pNumb IN NUMBER) RETURN VARCHAR2
         IS
              vRetval VARCHAR2(255);
              vNumb PLS_INTEGER;
         BEGIN
              vNumb := pNumb;
              vRetval := REPLACE(TO_CHAR(TO_DATE(vNumb,'j'),'jsp'),'-',' ');
              RETURN (vRetval);
         EXCEPTION
              WHEN OTHERS THEN
              RAISE;
         END;
    /*************** Only Available on 8i ********************************\
         FUNCTION Catcherr(pStr IN VARCHAR2) RETURN VARCHAR2
         IS
              LANGUAGE JAVA
              NAME 'catchErr.run(java.lang.String) return String';
         PROCEDURE runShell(pCmnd IN VARCHAR2, pErrMsg IN OUT VARCHAR2)
         IS
         BEGIN
              pErrMsg := Catcherr(pCmnd);
         EXCEPTION
         WHEN OTHERS THEN
              RAISE;
         END runShell;
    BEGIN
    getDir;
    END;

  • Run Host Command on UNIX

    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

    Hi Avi, thanks for your reaction. 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

Maybe you are looking for

  • OIM Provisioning - Error during OID Create User Task

    Hi, I am getting the following error during OIM Provisioning to OID (Create User Task). I added few more attributes to the OID_USR form and then to the "OID User" Process Definition. Also, I added the Code/Decode Key Values in AttrName.Prov.Map.OID.

  • J2EE_ADMIN has no Port Role in ABAP+JAVA stacks system

    I installed 2004s BI IDES SR2 with ABAP+JAVA on Win 2003 + Oracle, default client 800. I find the J2EE runs fine, I can log into SDM, configtools. And I can launch http://host:50000/index and http://host:50000/irj/portal, which mean the portal is up.

  • Adobe Flashplayer not responding even after the download says the installation is complete

    I have tried to go on several websites and view content - Youtube, Slacker, and some websites that I need for educational purposes. When I try to view contact or upload a song, I get a message stating that I need the latest version of the Adobe Flash

  • How to access Dictionary Structure in web dynpro(Where are you GS?) ?

    i had made one person Structure in Local dictionary. i had already this type of value node in my context. now i want to make an object of that type by code        IPersonElement person =wdThis.wdGetContext().createPersonElement(); Then it is giving m

  • Pages for ipad problem

    Hi. Im writing a multi page document using pages. the first page is text then all the rest are pictures only. I have gotten to page 4 but cant get any further. i cant gat a blank page 5 to apeaar. I tried getting the cursor to flash at the bottom of