Shell script to call sql script

Hi All,
I have a application server and want to make a shell script to call sql script.
Please let me know how to do the same.
Regards
Kumar

What is the platform you are using and you can give the path of the sql script in your shell script as follows
1.)first create .sql file...let it is table.sql and has the contents ...
create table test(x1 varchar2(20),x2 number(4),x3 date)
exit;
(2.) write a shell script...like table.sh in vi editor
Here login is scott/tiger@sid, or apps/apps@sid or whatever you know valid schema
echo enter the login
read login
sqlplus -s $login @table
(3.)run the script
$ sh table.sh
it will create the table in your particular schema

Similar Messages

  • How to call SQL Script in DBMS_SCHEDULER

    How to call SQL Scripts in DBMS_SCHEDULER?
    Things I got working
    1) Successfully created and tested a PL/SQL that was created under SQL Workshop->SQL Scripts (I named it 'TEST'). I was able to run this no problem.
    2) Successfully created a DBMS_SCHEDULER that runs every minutes. (See below)
    begin
      dbms_scheduler.create_job(
        job_name => 'myjob',
        job_type => 'plsql_block',
        job_action => 'null;',
        start_date => '19-JUL-11 03.10.00 PM', /* Remember to use the DB time, not your local time if not specifying a timezone */
        repeat_interval => 'freq=minutely',
        enabled => true);
    end;The problem i am having is to make the PL/SQL script (named 'TEST') runs every minute. Its probably very easy to do that but i dont seems like finding any examples online.
    I tried replacing the job_action attribute to " job_action => 'begin TEST; END;', " However, that did not work.
    I am stuck here for couple hours already, any clues would be great :)
    Thanks in advance
    John
    Application Express 4.1.0.00.32
    Edited by: John Lau on Aug 14, 2012 12:47 PM
    Edited by: John Lau on Aug 14, 2012 12:48 PM

    The PL/SQL is pretty long, I would like to call it from a different location rather then putting the whole coding as part of the argument. Sounds like I should be looking into procedure package in database?
    I will do some more research on procedure package, how to create one and how to call from it.
    Thanks
    John

  • Calling sql script from shell script

    Hi,
    I know this question has been asked many time in various forums, but I tried many combinations and not able to figure out what I'm missing.
    Basically - I'm trying to call a sql script from a shell script.
    This is my sql script (plsql.sql) -
    DELCARE
    v_empno NUMBER := '&empno';
    BEGIN
    select ename,sal from emp where empno = v_empno;
    dbms_output.put_line('Inside the plsql file');
    END;
    This is my unix shell script - I'm caling the plsql.sql file with the parameter passed(97882). I don't get any output. at least I should be able to view the dbms output if not for the sql query inside the sql script.
    #!/usr/bin/ksh
    sqlplus -s sam/olo01 << HERE
    @plsql.sql 97882;
    HERE
    What is it I am missing ?

    Using your scripts (and having to create and populate a table myself, that would have what your select statement implies),
    oracle:oklacity$ cat plsql.sql
    DELCARE
    v_empno NUMBER := '&empno';
    BEGIN
    select ename,sal from emp where empno = v_empno;
    dbms_output.put_line('Inside the plsql file');
    END;
    oracle:oklacity$ cat doit.sh
    #!/usr/bin/ksh
    sqlplus -s sam/olo01 << HERE
    @plsql.sql 97882;
    HERE
    oracle:oklacity$ ./doit.sh
    SP2-0042: unknown command "DELCARE" - rest of line ignored.
    SP2-0734: unknown command beginning "v_empno NU..." - rest of line ignored.
    oracle:oklacity$
    This is the kind of information you should have put in your opening post.

  • Not able to call sql script from shell program

    Hi Gurus,
    I am facing issue while calling sqlplus script from my shell program. Please find below my shell script. This program I've written and registered as for one of concurrent program
    in oracle applications.
    p_userid_passwd=$1
    p_appl_login=$2
    p_user_name=$3
    p_request_id=$4
    v_conc_request_id=${5}
    p_to_role=${6}
    p_from_role=${7}
    p_subject=${8}
    p_body=${9}
    p_dist_list=${10}
    v_request=${11}
    v_file_path_name=/u01/oraspt/REQUEST
    cd $APPLCSF/$APPLOUT
    echo "v_conc_request_id" $v_conc_request_id
    echo "p_to_role" $p_to_role
    echo "p_from_role" $p_from_role
    echo "p_subject" $p_subject
    echo "p_body" $p_body
    echo "p_dist_list" $p_dist_list
    echo "v_request" $v_request
    ls -l $v_request
    if [ $? -ne 0 ]
    then
       echo "No output request generated"
    else
       echo "Output request generated" 
    fi
    echo "connecting to ftp for placing out file to DB server"
    echo FTP to 99.60.17.11
    echo username: "oraspt"
    echo pw:        
    ftp -i -n 99.60.17.11 << EOF2
    user "oraspt" orakdk
    cd $v_file_path_name
    put $v_request
    bye
    EOF2
    output=`sqlplus -s /nolog <<EOT
    whenever sqlerror exit failure;
    connect  apps/apps
    set verify off;
    set serveroutput on size 120000;
           DECLARE
             l_errbuf      varchar2(300);
             l_retcode     varchar2(300);
           BEGIN      
            XXFND_SEND_MAIL.SEND_NOTIFICATIONS(  errbuf        => l_errbuf
                                               , retcode       => l_retcode
                                               , p_request_id  => $v_conc_request_id
                                               , p_to_role     => $p_to_role
                                               , p_from_role   => $p_from_role
                                               , p_subject     => $p_subject
                                               , p_body        => $p_body
                                               , p_dist_list   => $p_dist_list);
         EXCEPTION
            when others then
               dbms_output.put_line('Error encountered :'||SQLERRM);
         END;    
    EOT
    `
    echo "connecting to ftp for deleting output file"     
    echo FTP to 99.60.17.11
    echo username: "oraspt"
    echo pw:        
    ftp -i -n 99.60.17.11 << EOF2
    user "oraspt" orakdk
    cd $v_file_path_name
    delete $v_request
    bye
    EOF2
    echo "Deleted successfully"Output for script is as below
    v_conc_request_id 451906
    p_to_role DC.DKHOO
    p_from_role DC.DKHOO
    p_subject Receivable audit report10
    p_body Please find Audit Report Attachment.
    p_dist_list
    v_request o451906.out
    -rw-r--r-- 1 applspt dba 2368 Dec 28 15:06 o451906.out
    Output request generated
    connecting to ftp for placing out file to DB server
    FTP to 10.60.17.11
    username: oraspt
    pw:
    connecting to ftp for deleting output file
    FTP to 10.60.17.11
    username: oraspt
    pw:
    Deleted successfullyPlease let me know how to trigger pl/sql script.
    Thanks in advance for your help.
    Regards
    Nagendra
    Edited by: 838961 on Dec 27, 2011 11:25 PM

    Please find output as suggested, I've placed set -x in script.
    + p_userid_passwd=APPS/APPS
    + p_appl_login=1110
    + p_user_name=DC.DKHOO
    + p_request_id=451949
    + v_conc_request_id=451945
    + p_to_role=DC.DKHOO
    + p_from_role=DC.DKHOO
    + p_subject=Receivabless
    + p_body=report
    + p_dist_list=
    + v_request=o451945.out
    + v_file_path_name=/u01/oraspt/REQUEST
    + cd /u01/applspt/inst/apps/SPT_nfs-stg-app1/logs/appl/conc/out
    + echo v_conc_request_id 451945
    v_conc_request_id 451945
    + echo p_to_role DC.DKHOO
    p_to_role DC.DKHOO
    + echo p_from_role DC.DKHOO
    p_from_role DC.DKHOO
    + echo p_subject Receivabless
    p_subject Receivabless
    + echo p_body report
    p_body report
    + echo p_dist_list
    p_dist_list
    + echo v_request o451945.out
    v_request o451945.out
    + ls -l o451945.out
    -rw-r--r-- 1 applspt dba 2368 Dec 28 15:54 o451945.out
    + '[' 0 -ne 0 ']'
    + echo 'Output request generated'
    Output request generated
    + echo 'connecting to ftp for placing out file to DB server'
    connecting to ftp for placing out file to DB server
    + echo FTP to 10.60.17.11
    FTP to 10.60.17.11
    + echo username: oraspt
    username: oraspt
    + echo pw:
    pw:
    + ftp -i -n 10.60.17.11
    ++ sqlplus -s /nolog
    + output=Connected.
    + echo 'connecting to ftp for deleting output file'
    connecting to ftp for deleting output file
    + echo FTP to 10.60.17.11
    FTP to 10.60.17.11
    + echo username: oraspt
    username: oraspt
    + echo pw:
    pw:
    + ftp -i -n 10.60.17.11
    + echo 'Deleted successfully'
    Deleted successfully

  • Calling sql script in a folder

    Hi All,
    I'm calling a SQL script from a root SQL script which is present in a sub folder.
    root.sql
    Prompt Loading FULL_RECOMPILE.SQL
    SET DEFINE OFF
    @@Utils\FULL_RECOMPILE.SQL
    SET DEFINE ON
    Show errors
    commit;When I run the script I'm getting the following error.
    SP2-0310: unable to open file "UtilsFULL_RECOMPILE.SQL".
    I tried using forward / (@@Utils/FULL_RECOMPILE.SQL) and the script executed succesfully.
    Is there anyway I can execute the above script by using a backward slash?
    BANNER
    Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
    Thanks,
    guru
    Edited by: guru on 30-Jun-2010 05:54

    Your requirement seems to be executing the script present in the path:
    *./Utils/FULL_RECOMPILE.SQL*
    Is there anyway I can execute the above script by using a backward slash?Whats the need for using a backslash? Unix paths are separated by forward slash in contrast to windows.

  • Calling sql script from pl/sql block

    Hi
    I want to call a sql script from pl/sql block.
    like
    CREATE OR REPLACE procedure DataBaseExport(user_name in varchar2, pwd in varchar2)
    as
    begin
    execute immediate  '@ C:\Documents and Settings\umesh\emp.sql';
    end DataBaseExport;
    /

    Try something like this -
    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;
    CREATE OR REPLACE PROCEDURE Host_Command (p_command IN VARCHAR2)
    AS LANGUAGE JAVA
    NAME 'Host.executeCommand (java.lang.String)';
    --- THE PERMISSIONS ---
    call dbms_java.grant_permission('SYSTEM', 'SYS:java.io.FilePermission', '<<ALL FILES>>', 'read ,write, execute, delete');
    call dbms_java.grant_permission('SYSTEM', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
    call dbms_java.grant_permission('SYSTEM', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');And, finally,
    create or replace procedure call_sql_file(usr  in varchar2,
                                              pwd  in varchar2,
                                              host_str in varchar2)
    is
    begin
       host('sqlplus -s usr/pwd@host_str C:\UAX_Auto_Count.sql');
    exception
      when others then
        dbms_output.put_line(sqlerrm);
    end;Now, you can pass all the argument in order to execute that file.
    N.B.: Not Tested...
    Regards.
    Satyaki De.

  • Trouble calling .sql script

    I have looked on the forum for about a half an hour and can't find the exact answer I'm searching for, so here goes.
    I'm trying to update about a 100 records or so through use of an .sql script.
    I put the following in my sql script file
    UPDATE TABLE1 SET COL_NAME1 = 'some val.', COL_NUM_VAL = 12345, BOOL_VAL_COL = -1
    WHERE AUTOID = 9554 OR AUTOID = 1082
    OR AUTOID = 1305 OR AUTOID = 133
    OR AUTOID = 9124
    OR AUTOID = 8712
    OR AUTOID = 55 OR AUTOID = 6741 OR AUTOID = 9881
    OR AUTOID = 1012 OR AUTOID = 9158 OR AUTOID = 9378
    OR AUTOID = 9101 OR AUTOID = 8351 OR AUTOID = 7110 OR AUTOID = 922 OR AUTOID = 732
    OR AUTOID = 7253 OR AUTOID = 7825 OR AUTOID = 6772 OR AUTOID = 9854;
    commit;however, I get some kind of message back in the SQL Plus prompt showing.
      8  OR AUTOID = 9101 OR AUTOID = 8351 OR AUTOID = 7110 OR AUTOID = 922 OR AUTOID = 732
      9  OR AUTOID = 7253 OR AUTOID = 7825 OR AUTOID = 6772 OR AUTOID = 9854
    10* commit;
    11  /I can't really discern from this output stmt what happened or what is wrong,
    and needless to say, the update query doesn't execute. Any ideas as to what I need to put in there? And can't I just open it up in SQL Plus after I've created the sql file?Or is there more to it than that?
    I welcome any feedback.
    Thanks!
    Message was edited by:
    user515689

    Hi,
    If you have a file called foo.sql that contains just the 10 lines of code that you posted, then you can run it from SQL*Plus by saying "@foo" (depending on where foo.sql is stored. You may actually have give the full path name: e.g.
    SQL> @c:\my_folder\sub_folder\fooWhat are you doing to run the script?
    By the way, instead of all those ORs you can use the IN operator:
    UPDATE TABLE1 SET COL_NAME1 = 'some val.', COL_NUM_VAL = 12345, BOOL_VAL_COL = -1
    WHERE AUTOID IN (9554, 1082, 1305, ..., 9854);

  • Calling sql script from anonymous block

    Hi
    how to call an script from an anonymous block, like
    declare
    v_reccord_account number :=0;
    begin
    SELECT xx.cc INTO v_reccord_account FROM
    (select count(1) cc
    from accounts
    group by account_id
    having count(account_id) > 1
    )xx
    where ROWNUM=1;
    if v_reccord_account <1
    then
    dbms_output.put_line('no duplicates');
    ELSE
    < here i have to call this script -- @e:/test44.SQL >
    end if;
    end;

    Hi
    thanks for replying, i'm having some sql statements, i have to spool the results of those statements .. below is the content of the file i'm calling.
    =================================================
    whenever sqlerror exit sql.sqlcode
    set serveroutput on
    column fn new_value filename
    select 'remove_duplicates_'||to_char(sysdate, 'yyyymmddhh24miss')||'.log' as fn from dual;
    spool E:/&filename
    prompt 'Checking for duplicates'
    --select account_id, count(1)
    --from accounts
    --group by account_id
    --having count(1) > 1;
    prompt 'Records to be deleted'
    select *
    from accounts
    where decode ( substr(account_id,1,3),'COG',1,0)=1
    group by account_id
    having count(1) > 1;
    prompt ' Deleting duplicates'
    delete
    from accounts
    where account_id in (
    select account_id
    from accounts
    where decode ( substr(account_id,1,3),'COG',1,0)=1
    group by account_id
    having count(1) > 1
    commit;
    ==========================================

  • How to call SQL script from PL/SQL block

    Hi All,
    I have a pl/sql block from which i need to call a *.sql script file.
    Please tell me that how can i do this?
    Thanks and Regards.

    > Though just for knowledge sake, would you please tell if there is a way
    to call a sql script from a pl/sql block.
    This question stems usually from a confusion about client-server and which is which in Oracle.
    SQL*Plus is a client. PL/SQL is a server side language. SQL is a server side language.
    When entering either one of these two languages in SQL*Plus (or TOAD, SQL-Developer, etc), the content is shipped to an Oracle server process, is parsed there, and is executed there.
    The Oracle server process servicing the client can accept a single SQL statement or PL/SQL block at a time.
    It cannot accept a block of SQL statements delimited with a semicolon. That is a client concept where the client will read each delimited statement and send that, one after the other (in synchronous call mode) to the Oracle server for execution.
    The Oracle server does not have a "script parser". It understands SQL. It understands PL/SQL. And that is what it expects from the client.
    Whether the client supports the SET command, the HOST command, SPOOL command, ability to run scripts, and so... have no bearing on what the server itself is capable of doing. The server does not care what feature set the client has. It is tasked with servicing the client via SQL and PL/SQL.
    It is not tasked to support or emulate client features like running SQL scripts.
    Nor confuse PL/SQL with the very limited command set of SQL*Plus. The two has nothing in common. And just as PL/SQL cannot understand C# or Delphi commands, it cannot understand SQL*Plus commands.

  • Calling SQL scripts from subdirectories using SQL*Plus 9.2.0.1

    Is it possible to run an SQL script that in turn calls other SQL scripts from subdirectories? This seemed to work fine using SQL*Plus 8.1.7
    Did it break in 9.2.0.1?
    Any fixes available?

    Ryan,
    What exactly is your problem? Can you tell me any errors you are seeing? Platform?
    Alison

  • Calling sql script in plsql procedure

    Hello,
    I have a sql script named mytest.sql and i want to execute this from a stored procedure.
    following is the contents of this script
    spool d:\mytestsql.txt
    select * from tab;
    spool off
    Actually i want my sql script to run daily to export some tables data.
    I can execute this script from a sql prompt but i want to run it from enterprise manager.
    I am using oracle 10gR2 on windows2000 system.
    Any idea about scheduling the sql script to run automatically??
    How to execute this sql script from a plsql procedure??
    Thanks

    Hi all,
    Thanks for all the replies. I have found the solution with external procedures.
    Following is the complete step by step guide.
    1. Create the OSCommand Java Class using the following statement:
    connect as any user:
    create or replace and compile java source named oscommand as
    import java.io.*;
    public class OSCommand{
    public static String Run(String Command){
    try{
    Runtime.getRuntime().exec(Command);
    return("0");
    catch (Exception e){
    System.out.println("Error running command: " + Command +
    "\n" + e.getMessage());
    return(e.getMessage());
    2. Create the following Wrapper Function using the following statement:
    CREATE or REPLACE FUNCTION OSCommand_Run(Command IN STRING)
    RETURN VARCHAR2 IS
    LANGUAGE JAVA
    NAME 'OSCommand.Run(java.lang.String) return int';
    3. connect as sys
    Execute dbms_java.grant_permission( 'FKHALID','SYS:java.io.FilePermission', '<<ALL FILES>>','execute');
    execute dbms_java.grant_permission( 'FKHALID','SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '*' );
    execute dbms_java.grant_permission( 'FKHALID','SYS:java.lang.RuntimePermission', 'readFileDescriptor', '*' );
    commit;
    note: here fkhalid is the oracle user.
    connect as fkhalid user:
    Declare
    expdp_cmd Varchar2(2000);
    Begin
    expdp_cmd := OSCommand_Run('cmd /c sqlplus fkhalid@mtcedwt/pwd @d:\ORA_DUMPS\mydbexp.sql');
    DBMS_OUTPUT.Put_Line(expdp_cmd);
    End;
    In Unix
    Set Serverout On
    Declare
    x Varchar2(2000);
    Begin
    x := OSCommand_Run('/home/test/myoscommand.sh')
    DBMS_OUTPUT.Put_Line(x);
    End;
    I will check the dbms_scheduler also and will let you know the results.
    Thanks

  • Calling sql script through shell script

    Hi All
    I am trying to run one shell script it will execute the sql file which is in UNIX box. Problem here i am facing is
    when i submit the program through front end it taking time to execute and the status in running even for hours and hours. Manually i am terminating the concurrent program.
    But when same shell script when i tried to execute in putty it generating the output with in seconds
    Can you help what may be the error? I used the syntax like this
    Can you help what may be the error? need to change any syntax
    Thanks
    Prem Raj Dasari
    Edited by: Sravprem on Sep 20, 2012 12:43 AM

    Pl post details of OS, database and EBS versions. In your shell script, insert this line as the first line
    set -xthen run the concurrent program and paste the contents of the log of the concurrent program here
    HTH
    Srini

  • Tracking the order of execution of sql scripts in SQL*Plus

    In our production environment we sometimes have to run some .sql scripts in a particular order. Since the order of execution is important , i have created another .sql file caller caller.sql(shown at the bottom) which will call all the scripts in the right order.
    i thought of putting a exec DBMS_LOCK.SLEEP (5); after the end of every execution of the script so that i can see the
    'Ending script1'message .
    The spooling within the caller script(execute_stack.log) has become meaningless because each script has a spool <filename.log> and spool off within it. These spool logs (for every script) is important for tracking purposes as each script belongs to a different development team and i have to send them the spooled log file after the execution.
    I don't want to see the entire scripts running by in my screen. Since these scripts have their own spooling, i can later check the logs if the scripts where executed properly.
    So i need two things.
    1.I just need to see the following and nothing else in the screen.
    Ending script1
    Ending script2
    Ending script3
    .2. I need to log the order of execution. ie. the execute_stack.log should look like the above.Since there is a spool off within each script, this wouldn't be possible.Right?
    Ending script1
    Ending script2
    Ending script3
    .The caller.sql script which calls all the scripts in the right order
    alter session set nls_date_format = 'DD-MON-YYYY hh24:MI:SS';
    set serveroutput on
    set echo on;
    set feedback on;
    spool execute_stack.log
    @script1.sql
    exec dbms_output.put_line ('Ending script1');
    dbms_output.put_line(chr(10)||chr(10)||'.'||chr(10)||'.'||chr(10));
    exec DBMS_LOCK.SLEEP (5);
    @script2.sql
    exec dbms_output.put_line ('Ending script2');
    dbms_output.put_line(chr(10)||chr(10)||'.'||chr(10)||'.'||chr(10));
    exec DBMS_LOCK.SLEEP (5);
    @script3.sql
    exec dbms_output.put_line ('Ending script3');
    dbms_output.put_line(chr(10)||chr(10)||'.'||chr(10)||'.'||chr(10));
    exec DBMS_LOCK.SLEEP (5);
    @script4.sql
    dbms_output.put_line(chr(10)||chr(10)||'.'||chr(10)||'.'||chr(10));
    exec dbms_output.put_line ('Ending script3');
    commit;
    spool off;Is this a professional way of tracking the execution of .sql scripts?

    Pete_Sg1 wrote:
    Is this a professional way of tracking the execution of .sql scripts?No. There is very little professional about using .sql scripts on a production system - when stored procedures are safer, more robust, easier managed and controlled and secure.. and where a log table can be used to properly log the runtimes (and other stats) of each processing step.
    Let's just take a look at the number of moving parts you need to schedule and run a .sql script. A cron job needs to be configured with the proper environment setting. It needs to run a shell script. That shell script needs to load SQL*Plus. SQL*Plus needs to connect to the database (starting a dedicated server process most likely). SQL*Plus then needs to read a .sql file, parse these commands and either execute these locally (SQL*Plus commands) or remotely (PL/SQL and SQL commands).
    How can this be considered professional when the very same can be achieved with a
    - stored procedure
    - using DBMS_JOB to schedule the procedure for execution
    There are so many things that can go wrong with the first method. And so few things that could go wrong with the last one. No contest as to which method is not only better, but also professional.
    PS. See that you use Windows to run these scripts. It is even worse as it introduces another hardware and software layer making the scenario even more insecure & unsafe with more moving parts that can go wrong or simply fail.

  • INSERT Script stored as "SQL Statement Script" not firing on Oracle Alert

    We are using Alert Manager to run Alerts based on absence information in EBS R12.1.3 HR tables.
    Application: Human Resources
    Period/Event: Periodic
    Frequency: Every Day
    The Alert has 2 actions.
    One is to email a supervisor based on the Alert SQL finding staff who have had x number of absences over a set period of time.
    That is working fine.
    The other action is defined as an "SQL Statement Script".
    The SQL script inserts the variables defined in the SQL from the main Alert definition SQL, into a custom table.
    When the Alert fires, we are getting the email generated, but the INSERT statement isn't firing.
    However, when we look at the result of the Alert when it has run, and look at the steps which were fired, we can see the email step and the SQL step. When we look at the SQL in the SQL step which was generated, we can copy and paste it direct into TOAD and it works fine.
    We have tried a simple SQL INSERT statement which even just does:
    INSERT INTO xx_tmp (VALUE1_DATE, VALUE2) VALUES (SYSDATE, 'this');
    But even that does not work.
    We wonder if the issue is that we cannot do a direct INSERT from an alert type of "SQL Statement Script"?
    We have found another Alert which does a direct UPDATE on a table, but the SQL Statement Script definition has "Purchasing" as the Application, because it's updating a PO table.
    In our case, we're trying to insert into a custom table held in our in-house XX schema.
    Could the problem be that we don't have the "Application" set? If that's the case, we don't have a corresponding application anyway.
    Or can we not do a direct INSERT like this - do we need to use a package instead, and call that?
    Any advice much appreciated.
    Thanks

    Hi Brian,
    Alert issue - Custom SQL fix
    1. Define actions via "Actions" button on Alert Definition
    2. Create an action for e.g. "Send Message to Supervisor"
       Action type: message
       Action - sends email to people
    3. Create another action called e.g. "Insert Record"
       Action type: SQL Statement Script
       Fill in SQL in the "Text" section, no need to add a begin or end bit, just a simple INSERT INTO X etc ending with a semi colon
    4. Back on the main alert definition window, go to "Action Sets" button
       Here, need one SEQ for the Message / Email (e.g. Seq 1), and then click on "Action Set Details" and click on "Members" tab and select the "Send Message to Supervisor" Action
       Then close the "Action Set Details" window, and return to the "Action Sets" window
       click into 2nd line, add e.g. Seq 2, and call it e.g. "Insert Record", click on "Action Set Details" > Members tab and select the "Insert Record" The problem was that in the first instance, we had a single Action Set, and under "Members" had selected the "Send Message to Supervisor" and "Insert Record" at the same time.
    Short answer: each Action needs to be defined as a separate line in the Action Sets definition.
    I can send screenshots if you need them, and don't mind putting your email address on this forum.
    You can always edit the thread after I've emailed you, to remove your email address.

  • Replace Text In SQL Scripts

    Hi,
    I would like to search and replace text in files when I run .sql files.
    E.g. When user provide scripts xyz.sql, they would put table name like
    INSERT INTO  xyz abc VALUES ('text');I would like to replace xyz abc with mytablename.
    INSERT INTO  mytablename VALUES ('text');Besides, from the user provided sql scripts, they would be some junk create table scripts, I would like to comment off these junk table scripts.
    How could I do achieve the above?
    I would be calling user provided sql scripts from my sql scripts using @ ./data/temp.sql
    I am using oracle 8i for these. Any help is highly appreciable.
    Regards

    Sorry for not providing enough information.
    Oracle Version as follows:
           Oracle8i Enterprise Edition Release 8.1.7.4.0 - Production
         PL/SQL Release 8.1.7.4.0 - Production          OS:
    Windows XP SP2
    damorgan wrote:No clear description of what you are actually trying to do ... for example where does "mytablename" come from, where does "xyz" come from, how is the decision to be made? Based on what logic?
    These scripts are provided by customers where they use other database like sysbase to generate sql scripts and customers are not in a position to change or alter the scripts as these scripts are part of the solution provided by vendors(legacy systems)
    I have mapping sql script where table name is e.g. xyz abc then use script TS2 and process the customer given sql script.
    Let me know if I am missing out any other information.
    Regards

Maybe you are looking for