Host command from sqlplus based on a condition

I am on an Oracle 10.2.0.3.0 database running on sun solaris.
Am using my sqlplusw on my windows xp professional to do the below :
SQL> select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for Solaris: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
I have 4 variables declared in sqlplus for which I get my values from anonymous pl/sql blocks :
print db1_status;
DB1_STATUS
3
print db2_status;
DB2_STATUS
0
print db3_status;
DB3_STATUS
1
print db4_status;
DB4_STATUS
0
I needed some help with doing this :
Based on the values of each these variables, I wanted to invoke the host command to run stuff like
if db1_status = 3 then
host ...something
if db2_status = 0 then
host ...something
I am looking for a way to do this without creating an external procedure or java stored programs. Are there any?
Thanks

Need to use a batch file (.bat) to utilize SQL Plus while generating the SQL statements within the .bat file.
Example:
Inside SQL Plus
SQL> create table testme (name varchar2(255), value number(5));
Table created.
SQL> insert into testme(name, value) values ('db1_status', 3);
1 row created.
SQL> insert into testme(name, value) values ('db2_status', 0);
1 row created.Create a .bat file (Using test.bat)
test.bat
@echo off
echo select value from testme where name = 'db1_status';>temp.sql
echo exit >> temp.sql
sqlplus -S %2/%3@%1 @temp.sql > result.dat
for /f %%x in ('more result.dat') do set RESULT=%%x
if "%RESULT%" == "3" goto :DB1_STATUS_3
if not "%RESULT%" == "3" goto :DB1_STATUS_NOT_3
goto :EOF
:DB1_STATUS_3
echo db1_status = 3
**ENTER SYS COMMANDS HERE**
goto :EOF
:DB1_STATUS_NOT_3
echo db1_status != 3
**ENTER SYS COMMANDS HERE**
goto :EOF
echo select value from testme where name = 'db2_status';>temp.sql
echo exit >> temp.sql
sqlplus -S %2/%3@%1 @temp.sql > result.dat
for /f %%x in ('more result.dat') do set RESULT=%%x
if "%RESULT%" == "0" goto :DB2_STATUS_0
if not "%RESULT%" == "0" goto :DB2_STATUS_NOT_0
goto :EOF
:DB2_STATUS_0
echo db2_status = 0
**ENTER SYS COMMANDS HERE**
goto :EOF
:DB2_STATUS_NOT_0
echo db2_status != 0
**ENTER SYS COMMANDS HERE**
goto :EOF
:EOF
del temp.sql
del result.dat
@echo onAs you can see, this is a simple if/then which takes the value from a dynamically created SQL file (temp.sql) and uses it do determine the next system commands to execute.
Hope this is what ya needed.
-Tim

Similar Messages

  • 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

  • Host command from D2K Forms

    Am calling the sql loader (sqlldr73) using HOST command from D2K Forms 4.5.
    my code has following sequence,
    <sequence of stmts 1>
    Host(....);
    <sequence of stmts 2>
    the stmts(<sequence of stmts 2>) following the call to HOST commant should be executed only after successful execution of the sql loader.
    curently the sql loader and stmts(<sequence of stmts 2>) are running parallely
    Is there any work around?

    Hi,
    Better way to do it would be to write a batch / shell script with the sequence of statements you want to execute and call the batch file using the host command.
    Regards,
    Arun

  • Running unix commands from sqlplus

    I will like to change my directory from sqlprompt. What is the command to do that?
    SQL>

    Don't think you can do what you want. The 'host' or '!' command in sqlplus spawns another shell, as soon as it returns the settings are back to the parent shell "the one that started sqlplus".

  • Host Commands from Java

    Hello everyone,
    I'm trying to run openVMS host commands via Java using the code listed below, which essentially runs the following host commands, each in turn:
    terry :== "hello"
    sho sym terry
    sho log robin4
    I've tried a few other commands as well, but the ones which assign variables (such as the terry example above), never work, either producing no output as in the example above, or if I did
    define/group "hello" terry
    would produce:
    DCL-W-NOCOMD, no command on line - reenter with alphabetic first character
    So commands that don't print anything to the screen are the ones that are causing problems (they're just setting variables or what not).
    Does anyone have any ideas as to how to get these commands working via java? I really don't know what to think..I've tried checking the format of the commands I'm trying to do, and it's not down to that - the host command I'm running is right and works if done directly.
    Please help! Thank you so much in advance.
    Robin
    import java.io.*;
    public class Host {
    public static void executeCommand(String command) {
    String s = "hello";
    String s2 = "sho log robin4";
    String s3 = "assign/system "+command+"hello"+command+" robin5";
    try {
    String[] finalCommand;
    System.out.println(System.getProperty("os.name"));
    finalCommand = new String[3];
    finalCommand[0] = "terry :== \"hello\"";
    finalCommand[1] = "sho sym terry";
    finalCommand[2] = s2;
    for(int i = 0;i< finalCommand.length; i++){
    // 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(ex.getLocalizedMessage());

    User_resU wrote:
    Hello everyone,
    I'm trying to run openVMS host commands via Java using the code listed below, which essentially runs the following host commands, each in turn:
    terry :== "hello"
    sho sym terry
    sho log robin4
    1. Presumably this represents some sort of character user interface (CUI) which is console based.
    finalCommand = new String[3];
    finalCommand[0] = "terry :== \"hello\"";
    finalCommand[1] = "sho sym terry";
    finalCommand[2] = s2;
    final Process pr = Runtime.getRuntime().exec(finalCommand);
    2. This represents an executable to which you are passing command line arguments.
    This isn't a java problem because 1 and 2 are not even close to being the same.
    Java won't do anything that you cannot get the application to do itself.
    Your choices:
    1. Find a way to run the app such that it takes commands from a file. You put the commands in a file and pass that to exec()
    2. Find a way that use stdio (the CUI might represent that but there is no guarantee.) You then use exec() to start the app then use the IO streams to pass the commands to it.
    Notice that my choices do not include an option for passing as command line parameters because I am almost certain that it does not exist.

  • How to run a HOST command from Report 2.5

    Hello everybody,
    I want to pass an unix command from a Report. I am running the report (Report 2.5) on an Unix server and I want to pass a unix host command inside the Before Report Trigger of the report. But Report2.5 is not recognising the HOST built-in. Is there is any way around?
    Thank in advance.
    Samujjwal Basu

    First off is that openssl command correct? Should it be this instead:
    openssl pkcs8 -inform der -nocrypt -in test.der -out result.pem
    Try out your openssl command within a command prompt so that you know that it works ok. I think the command line you specified waits on stdin (well it does for me).
    After that.....
    runtime.exec creates a Process object. If you do this:
    Process openssl = runtime.exec("....")
    then you can examine the return code from openssl to see the exit code - for instance if the input file does not exist then exit = 1. You can test for this with Java
    Alternatively you could get the stderr from the process and look inside it - if it is 0 length then all is good, if it has some text in there then it has likely failed. You could then throw an exception and include the stderr output in the exception messgae. You may need to experiment with this, runnig it first when openssl is happy then running it again when openssl is upset.
    M

  • 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.

  • How to simulate HOST command from DB Procedure

    Hi,
    I'm using Oracle 9.2 database on Win2000 PC.
    I need to start .bat file from a database procedure. More generaly how to simulate HOST command that I'm using from Forms6i.
    Thanks,

    Thanks for the reply,
    But, I am able to successffuly execute HOST from SQL+
    only from the PC where the database is, not from the client. My .bat file is on the server side.
    From the procedure I was not able to run it in either cases
    Procedure TEST
    IS
    BEGIN
    EXECUTE IMMEDIATE 'host C:\MYBATCHFILE.BAT'
    END;
    returns ORA-00900 INVALID SQL STATMENT
    with EXECUTE IMMEDIATE '$ C:\MYBATCHFILE.BAT' returns Invalid Character Error.
    BR,

  • 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

  • Call HOST command FROM FORMS 4.5 AND 6.0

    I have a problem that I found out about yesterday, and have no idea how to fixe it.
    I created a form to run on form 4.5.9.7 In this form i call up the host command, but it does not work properly, because by using the host oracle stops there until i close the application that i called with the host, it hangs there. But now it doesn't do it, once the host is executed, it continues the rest of the code that i have, which should not.
    On the same computer i created another form on forms 6.0.5.2 and call the host command again, and finally it worked perfect! I mean until the program called by host command is running forms does not continue, it hangs there.
    Could someone explains me that please, is there some patch I need on forms 4.5?
    null

    We converted forms from 4.5 to 6.0. Basically all you have to do is recompile the forms. but, the very first thing you have to do is recompile all the libraries. The forms will not work if you don't recompile the libraries first. So, open and compile the libraries in 6.0, then open and compile the forms in 6.0. They should then work fine. If they do not, try deleting and reattaching the libraries and compile again.
    Good luck.

  • HOST command in SQLPlus

    Hi everybody
    I have a script with two HOST commands inside one script. The problem is that the second host command is executed just before the first host command terminates. Is there a way to make the second waits till the first ends ?
    Thanks to all

    hi.
    I schedules my exports through crontab..
    I create a script for each schema export job and submit them to cron and it automatically runs the export as I scheduled them.

  • Fetching Values from Ancestors based on UDA condition

    Hi,
    I have a typical requirement where I  need to fetch data from the ancestor based on a particular UDA condition.
    For ex: See the below exhibit
    Dimension
    ----A (UDA: xyz)
    -------B (UDA: xyz)
    ------------C
    -----------------D
    -----------------E (UDA: xyz)
    -----------------F
    Requirement: (Should be a member formula on a particular Account member - No calc script)
    1- Calculations should happen only for members with UDA 'xyz'
    2- The value for member 'E' should come from its first immediate ancestor with same UDA as'E' has - in the above case the value of 'E' should be from member 'B' (and not 'A')
    similarly while calculating member 'B', it should take value from member 'A'
    I have tried the member formula like:
    @ANCEST(DimName,@Currmbr(Dimname)) AND @UDA(DimName,'xyz)
    but this gives 'DOUBLE VALUE STRING' error.
    Can anyone help me with how I should develop the logic for this requirement.
    Thanks again.

    DEAR ALL !
         I HAVE SOLVED THE ISSUE BY USING ANOTHER BAdI " HRBAS00_STRUAUTH".
    THANKS AND REGARDS,
    S.SURESH

  • How to exe OS command from sqlplus

    I used to exe OS command with ! in sqlplus in older version of Oracle. I just installed 10g Express and I tried !dir, and got the following error:
    SQL> !dir
    SP2-0042: unknown command "!dir" - rest of line ignored.
    Did I do something wrong?

    host seems to work in special cases
    On Microsoft Windows XP
    where dirme.bat contains
    dir
    host d:\path\to\dirme.bat
    results in output of dir
    whereas host dir
    results in an exception java.lang.ProcessImpl.create(Native Method)
    at oracle.dbtools.raptor.scriptrunner.commands.Host.handleEvent(Host.java:30)
    Works in Linux (for host ls)
    Could be a path/built in dos command problem.
    What is other peoples experience?
    -Turloch

  • Deleting Request from cube based on Selection Condition

    HI All,
    I have a scenario where i have three selection condition while i update from ODS to CUBE . I keep getting differnet versions of the file so the latest version should replace the old version , to do this i tired using the option
    Delte Request from Info Cube after Update in the Data Tagets tab
    And the Radio button Overlapping is checked  . ( This is not working )
    The three selection conditions in Info Pacake are
    Reduest id from ODS : 11111
    Cal Month                 : 20072
    File Type                   : B
    The selecion condition for the second Version in Info Pacake of the same file that should replace the first file in cube is
    Reduest id from ODS : 22222  ( The request id is RID in the ODS for second file )
    Cal Month                 : 20072
    File Type                   : B
    so can any one let me know how can i achvie this ........

    Hi Abraham,
       You select the variable deletion conditions when you schedule the InfoPackage that is going to load the new data. On the Data Targets tab page in the Automatic Deletion of Similar/Same Requests from InfoCube column, you click on the pushbutton to go to the Deletion of Requests from the InfoCube After Update dialog box.
    Here you determine under which conditions existing requests are deleted from the InfoCube:
    ·        You can include update modes, InfoSources, DataSources, and source systems for requests.
    Example
    Requests are deleted when the appropriate deletion conditions are met if existing requests and new ones were loaded from the same DataSource.
    ·        You can determine whether the selections for the new request need to be the same as or more comprehensive than the selections of the request that is to be deleted, or whether the selections for the new request need to completely or partially overlap the selections of the request that is to be deleted.
    ·        You can specify deletion restrictions according to date. This means that, when the deletion conditions are met, only those requests that were loaded within a specific time period are actually deleted.
    Example
    If you choose Data for the Request from the Last Seven Days, only those requests are deleted that have been loaded in the last seven days.
    ·        You can specify situations in which a request is not to be deleted, even if the appropriate deletion conditions are in place.
    Example
    If, under Exceptions, you choose the Today is …the Last Day of a Month, existing requests are not deleted, if the new request is loaded on the last day of a month.
    ·        Another option for determining deletion conditions is creating a user routine for the InfoPackage and the InfoCube.  In this routine you can exclude requests from a deletion process or include additional requests for deletion.
    Check conditions again, it will work, if selection and data source is same.
    Hope it Helps
    Srini

  • How to run Unix Host commands from Database Triggers?

    Hi
    I need to create few directories in the Unix O/s under a specific directory (From a Database Trigger). And the directory names will be determined in the DB Trigger based on the data.
    I hope someone would have come across a requirement like this and will be able to help me out.
    Thanks.
    Mohan

    Hi Christopher
    How is it possible to use System calls from Triggers. Is it possible to use Runtime Libraries in DB Triggers.
    Thanks
    Mohan
    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Christopher Racicot ([email protected]):
    Try using the system calls available in
    the C runtime library by calling an external
    C procedure from the trigger. We will be
    enhancing the support in UTL_FILE to address
    issues like this in an upcoming release,
    but for now an external procedure should
    do the trick.<HR></BLOCKQUOTE>
    null

Maybe you are looking for