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.

Similar Messages

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

  • How to execute unix command line from cocoa?

    how to execute unix command line from cocoa?
    for example, if I want to call "ping" from cocoa, how should I do it? and how can I obtain the return value?
    thank you.
    Power G5 Quad Mac OS X (10.4.3)

    The following article may also help:
    http://cocoadevcentral.com/articles/000025.php
    Mihalis.
    Dual G5 @ 2GHz   Mac OS X (10.4.6)  

  • How to execute a Command Prompt command from J2SE code executing on Windows

    How to execute a Command Prompt command from J2SE code executing on Windows??
    Please help me

    [http://java.sun.com/docs/books/tutorial/getStarted/]
    ~

  • How to execute Linux command from Java app.

    Hi all,
    Could anyone show me how to execute Linux command from Java app. For example, I have the need to execute the "ls" command from my Java app (which is running on the Linux machine), how should I write the codes?
    Thanks a lot,

    You can use "built-in" shell commands, you just need to invoke the shell and tell it to run the command. See the -c switch in the man page for your shell. But, "ls" isn't built-in anyays.
    If you use exec, you will want to set the directory with the dir argument to exec, or add it to the command or cmdarray. See the API for the variants of java.lang.Runtime.exec(). (If you're invoking it repeatedly, you can most likely modify a cmdarray more efficiently than having exec() decompose your command).
    You will also definitely want to save the returned Process and read the output from it (possibly stderr too and get an exit status). See API for java.lang.Process. Here's an example
    java.io.BufferedReader br =
    new java.io.BufferedReader(new java.io.InputStreamReader(
    Runtime.getRuntime().exec ("/sbin/ifconfig ppp0").
    getInputStream()));
    while ((s = br.readLine()) != null) {...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to execute  make  Command?

      Run in the terminal inside the  make command,prompt:"-bash:make:command not found"  My system version is Mac OS X 10.7.3 Xcode Version is 4.3.
      How to execute  make  Command?
                                    thanks!!

    I switch to / usr / bin directory also did not find the make  only to find a makeinfo. Google to find relevant information, if installed Xcode will be able to run make, but now does not work.
    But still thank you very

  • How to execute Dos Command 'Pause' from Java ?

    How to execute Dos Command 'Pause' from Java ?
    I have read the article in javaworld for Runtime.exec() anomalies.
    Can someone please give an insight on this?

    Thanks Buddy!
    That was very useful. Even though its a simple
    solution, I never thought about that.Bullshit! Reread reply #7 of http://forum.java.sun.com/thread.jspa?threadID=780193

  • How to execute external command?

    How to execute follow command and get its ouput on linux ?
    $ grep processor /proc/cpuinfo | wc -l

    sabre150 wrote:
    nitelia wrote:
    String[] command = {"sh","-c","grep processor /proc/cpuinfo | wc -l"};
              Process pro = Runtime.getRuntime().exec(command);
              BufferedReader bf = new BufferedReader(new InputStreamReader(pro
                        .getInputStream()));
              String x = null;
              while ((x = bf.readLine()) != null) {
                   System.out.println(x);
         This should workWow! So all one has to do is to use a shell to run the command! Isn't it a pity I did not give this solution in reply #3?You old sabre rattler! ;-)

  • Calling java host command in trigger/PLSQL

    I created a java call to execute a linux host command that calls a shell script that will echo out a result. It is owned by SYS and has granted execute to SYSTEM. SYSTEM has a table that monitors accesses to the RDBMS. When a user logs on from a remote server vis sqlplus, this LOGON trigger write to the SYSTEM table (successfully). SYSTEM has a trigger that runs a linux command to execute a shell script that pulls the actual IP address from the remote system. I can run this call from a PLSQL block (outside the trigger) and get a response back like "user:101.101.101.111" but when I have the same user log on, the trigger fires - no errors or exceptions yet no rows are returned. Is there some restriction in a trigger versus just a plsql block call? The java code used is what I found on (http://www.oracle-base.com/articles/8i/ ... mPLSQL.php) and it works perfectly OUTSIDE the trigger but nothing is returned in the trigger firing steps. Any idea?
    rdbms: 11.1.0.7, Redhat 4
    I know the code works because I can write the host command output to a file. Later in the trigger I can open the file and can read the data that should have been returned in the java host call.

    FYI - here is the code from your site that I used:
    DROP JAVA SOURCE SYS."Host";
    CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED SYS."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("Cmd results: " + 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("Cmd Error: " + 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;
    /

  • How to Execute shell commands in OSB

    Team,
    My Requirement:
    I have two sftp servers name ServerA and ServerB. Need to copy files from ServerA and place it on ServerB and change the file permissions to 777 after placing the files.
    The user i am connecting to ServerB has the access to override file permissions.
    Steps
    1. With help of FTP adapter in OSB I am reading files from ServerA and writing on to ServerB  -- Completed and is working.
    2. How to override file permissions after placing the file ????? -- Yet to implement.
    Please suggest me how can i accomodate 2nd step.
    Thanks,
    Suman V.

    If by "execute shell commands" you mean actually
    running a shell process (as opposed to just forking
    and executing specified programs) then I'd advise
    against it. The last thing you want is for the
    clients to be running arbitrary commands on the
    server. You don't want to make it possible for the
    client to run "rm -fr /" on your server.Right.
    I was assuming (perhaps with more optimism than is really warranted) that the OP was going to be in complete control of which commands were executed--that there'd be a small, fixed set in response to certain user actions.

  • How to execute unix command through odi and store the result in table

    I have to reconcile  if data is loaded in table from csv file or not . I have to create a oracle data integrator package/interface/procedure to execute unix command to count number of rows in the csv files and store the count result in a table then i have to query the loaded table and count number of rows there and store in the table and have to compare is counts are same or not,  Please assist me how to make package/interface/procedure to  execute unix command and store result in oracle table.
    Thanks in Advance

    Use ODI OS command tool in the ODI package.
    create an interface in ODI using LKM File to Sql and the output file generated with the csv file's row count as a source and the db table(where the count needs to be stored) as a target

  • How to execute unix command in plsql block( urgent)

    Hi All,
    i want rename the unix folder to New name on update non_employee table . So, please give me idea how to use unix command here.... Please suggest me ASAP ... Its urgent
    CREATE or REPLACE TRIGGER NON_EMPLOYEE_AftUpd_trg
    AFTER UPDATE ON NON_EMPLOYEE
    FOR EACH ROW
    BEGIN
    IF :new.DIST_LIVELINK_PATH <> :old.DIST_LIVELINK_PATH THEN
    rename unixfolder1 to :new.dist_livelink_path.
    end IF;
    END;

    The solution will depend a lot on your Oracle version, which you forgot to mention ;)
    btw shouldn't that be (in pseudocode)
    rename :old.dist_livelink_path to :new.dist_livelink_pathotherwise it will always fail after the first time?
    In Unix that would require the mv command.

  • How to execute OS command on client's machine

    Hi,
    How to invoke for example MsWord on client's machine from APEX?
    I'm trying to use MSWord mail merge.
    Andrija

    Hello Andrija,
    I did it without Oracle BI. BI is $40,000 per processor.
    I'll sell it for less ):
    A little different !!!:
    1. I am using Office 2007
    2. I use HOST command on the server.
    Ok, here how I did it.
    1. Create Word 2007 template with XML token defined and store it in the database, which will be dynamically replace by the database values selected.
    2. Create the HOST command procedure using JAVA, which you can find example in this forum.
    3. Create Oracle DIRECTORY to point to a physical directory on Windows, UNIX or Linux
    4. Create a "customXml" under this directory.
    5. Retrieve your WORD template and put it in the Oracle DIRECTORY
    6. Output your data into a XML format to "customXml" directory
    7. use "$ORACLE_HOME/bin/zip" to zip this 2 files together.
    8. Return the WORD doc to the screen.
    9. Here you go
    --John                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to use host command for creating folders

    i want to create a folder called abc in my C drive using forms 6i.
    how can i do it using Host command?

    Host('MD C:\ABC');Francois

  • How to execute dos command in Java program?

    In Perl, it has System(command) to call dos command.
    Does java have this thing?
    or any other way to execute dos command in java program?
    Because i must call javacto compile a file when the user inputed a java file name.

    Look in the Runtime class, it is implemented using the Singleton design pattern so you have to use the static method getRuntime to get its only instance, on that instance you can invoke methods like
    exec(String command) that will execute that command in a dos shell.
    Regards,
    Gerrit.

Maybe you are looking for

  • Importing sets "part of compilation" all the time, even when it shouldn't.

    I've just instaled iTunes 9.01 and have been importing about 5 CDs worth of music. The problem is that iTunes seems to be setting the "part of a compilation" flag every time even though none of the CDs I've been importing are compilations CDs. I know

  • Payment document vs clearing document

    Dear All, What is the difference between payment document and clearing document,in which business scenario's we will use them. Thank you. Regards, D vasanth

  • How do I print a page of return labels in Address Book?

    How do I print a page of return labels in Address Book?

  • Vista Aero and MacBook

    Hello! I'm running Vista Ultimate using BootCamp on my MacBook. Even thought the systems requirements seem to support it, I can't seem to get Aero to work. Any suggestions? Thanks!

  • Bug with rules in Apple Mail

    There is a bug when it comes to rules in Mail in 10.6.4 and 10.6.5 (and possibly earlier versions of Mail as well). Here are the steps to reproduce the bug: 1. Make sure you have an IMAP account in Mail. 2. In your IMAP account's Mailbox Behaviors, U