How to execute a sql script in dbms_job?

how to execute a sql script in dbms_job?

See my response to Re: how to execute a sql script file in procedure or trigger.
Cheers, APC

Similar Messages

  • How to execute a .SQL script file?

    Hi
    I'm sure this question has been answered already, however I was unable to find an answer using the search tool.
    Using c# I'd like to run a .sql file. The sql file contains multiple sql statements, some of which are broken over multiple lines. I tried reading in the file and tried executing the file using ODP.NET ... however I don't think ExecuteNonQuery is really designed to do this.
    So I tried using sqlplus via spawning a process ... however unless I spawned the process with UseShellExecute set to true sqlplus would hang and never exit. Here's the code that DOESN'T WORK.
    Process p = new Process();
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.RedirectStandardOutput = true;
    p.StartInfo.FileName = "sqlplus";
    p.StartInfo.Arguments = string.Format("xx/xx@{0} @{1}", in_database, s);
    p.StartInfo.CreateNoWindow = true;
    bool started = p.Start();
    p.WaitForExit();
    WaitForExit never returns .... Unless I set UseShellExecute to true. A side effect of UseShellExecute is that you can no capture the redirected output.
    This must be such a common thing to do, I'm hoping someone has a solution to this.
    Thanks
    Rich

    If by "SQL script" you mean run a program that resides outside the database (a file of the format whatever.sql) then the answer is with difficulty. We can use extproc calls to run c libraries or embedded java to execute host-style commands but it's a lot of pfaffing about.
    The easiest solution is to bring the SQL commands into the database as a stored procedure. If you still need to be able to run the script externally then rewrite that to call the same stored procedure. However, if the .SQL file includes OS calls then you will have to choose either Java or extproc, depending on what it is the script actuually does. If you want more focused advice you'll need to give us details.
    Cheers, APC

  • How to execute a  .sql file from a batch file

    Hi all
    I've to take backup of a database weekly twice on every wednesday & Friday @ 5pm IST. I've written a hot backup script, which works every well.
    now i want to automate the script. ie i want this script to run on wednesday & friday @ 5pm without any human interfearance ie with out actually any1 executing this script.
    i created a batch file prod.bak with the following lines
    @echo off
    set oracle_sid=testdb
    set oracle_home=d:\oracle\ora92
    sqlplus /nolog
    connect sys as sysdba/oracletest@testdb
    this batch file when eexecuted connects me to sql prompt.
    Now i want to execute my backup script bkp.sql automatically when it is connected to sql prompt.
    (i tried with these lines in the above batch file...
    call bkp.sql---it just opens the bkp.sql file in notepad & displays the script
    start bkp.sql---same as call
    connect / as sysdba/pwd@[email protected] --- does not work simply remains a the sql prompt.
    At 17:00 /Every:w,f "d:\bkp.sql"---does not work simply remains at the sql promt.)
    Can any1 let me know what should i write in the batch file that will execute the bkp.sql file automatically after it gets connected to sql prompt. M using oracle 9i.
    I'll manage he time through windows utility of scheduling task.. Let me know how to execute the .sql file from a batch file.
    Thanks
    Tripti

    Try
    sqlplus "sys/oracletest as sysdba" @bpk.sql
    Working locally, and having set the ORACLE_SID, you don't need to specify the SqlNet alias (@testdb).
    Remember to put an exit at the end of the bpk.sql script.

  • How to execute a SQL procedure in UNIX

    How to execute a SQL procedure in UNIX

    Check this out..
    -Sri
    << a.sql >>
    create or replace procedure junk(nout out varchar2) is
            x varchar2(20);
    begin
            select 'Sam' into x
            from dual;
            nout := x;
    end;
    << Shell script >>
    sqlplus -s / << DOC
    scott/tiger
    variable x varchar2(20);
    set autoprint on
    @a.sql
    begin
    junk(:x);
    end;
    exit
    DOC
    << Execution of Shell SCript >>
    # sh b.sh
    Procedure created.
    PL/SQL procedure successfully completed.
    X
    Sam

  • How to run the SQL Script in SQL Prompt?

    Hi ExpertGroup,
    I have written one SQL Script name called "MySQLSCript.SQL". I want to know how to run the SQL Script in SQL Prompt?.
    Generally, I run SQL Script in PL/SQL Developer tool. But In this case, some SET command is not working/supporting in PL/SQL Developer Tool.
    Let me know, How to Run in SQl Prompt.
    Thanks & Regards,
    Senthil K Kumar.

    This is my SQL Script....
    SET COLSEP '|'
    SET LINESIZE 32767
    SET PAGESIZE 50000
    /* SET LINESIZE 3000
    SET PAGESIZE 50000
    SET DEFINE OFF */
    SET ECHO OFF
    SET FEEDBACK OFF
    --SET HEADING OFF
    SET TRIMSPOOL ON
    SET NEWPAGE NONE
    SET UNDERLINE OFF
    SPOOL &&EnterPath;
    SELECT * FROM &&TableName;
    SPOOL OFF
    SET FEEDBACK ON
    --SET DEFINE ON
    PROMPT Done.
    I am able to run this script in SQL Prompt....
    Its executing fine...
    But, If I am executing again it maynot asking for new set of data....
    alternativily its taking old values only.....
    how can i exeute with new set of data in the sql prompt.....

  • How to execute an SQL query present in a string inside an ABAP program?

    hello,
    How to execute an SQL query present in a string inside an ABAP program

    Raut,
    You can execute Native SQl statements.
    Ex: To use a Native SQL statement, you must precede it with the EXEC SQL statement, and follow it with the ENDEXEC statement as follows:
    EXEC SQL [PERFORMING <form>].
      <Native SQL statement>
    ENDEXEC.
    There is no period after Native SQL statements. Furthermore, using inverted commas (") or an asterisk (*) at the beginning of a line in a native SQL statement does not introduce a comment as it would in normal ABAP syntax. You need to know whether table and field names are case-sensitive in your chosen database.
    In Native SQL statements, the data is transported between the database table and the ABAP program using host variables. These are declared in the ABAP program, and preceded in the Native SQL statement by a colon (:). You can use elementary structures as host variables. Exceptionally, structures in an INTO clause are treated as though all of their fields were listed individually.
    If the selection in a Native SQL SELECT statement is a table, you can pass it to ABAP line by line using the PERFORMING addition. The program calls a subroutine <form> for each line read. You can process the data further within the subroutine.
    As in Open SQL, after the ENDEXEC statement, SY-DBCNT contains the number of lines processed. In nearly all cases, SY-SUBRC contains the value 0 after the ENDEXEC statement. Cursor operations form an exception: After FETCH, SY-SUBRC is 4 if no more records could be read. This also applies when you read a result set using EXEC SQL PERFORMING.
    EXEC SQL PERFORMING loop_output.
      SELECT connid, cityfrom, cityto
      INTO   :wa
      FROM   spfli
      WHERE  carrid = :c1
    ENDEXEC.
    Pls. Mark If useful

  • How to execute this SQL Query in ABAP Program.

    Hi,
    I have a string which is the SQL Query.
    How to execute this sql Query (SQL_STR) in ABAP Program.
    Code:-
    DATA: SQL_STR type string.
    SQL_STR = 'select * from spfli.'.
    Thanks in Advance,
    Vinay

    Hi Vinay
    Here is a sample to dynamically generate a subroutine-pool having your SQL and calling it.
    REPORT dynamic_sql_example .
    DATA: BEGIN OF gt_itab OCCURS 1 ,
    line(80) TYPE c ,
    END OF gt_itab .
    DATA gt_restab TYPE .... .
    DATA gv_name(30) TYPE c .
    DATA gv_err(120) TYPE c .
    START-OF-SELECTION .
    gt_itab-line = 'REPORT generated_sql .' .
    APPEND gt_itab .
    gt_itab-line = 'FORM exec_sql CHANGING et_table . ' .
    APPEND gt_itab .
    gt_itab-line = SQL_STR .
    APPEND gt_itab .
    gt_itab-line = 'ENDFORM.' .
    APPEND gt_itab .
    GENERATE SUBROUTINE POOL gt_itab NAME gv_name MESSAGE gv_err .
    PERFORM exec_sql IN PROGRAM (gv_name) CHANGING gt_restab
    IF FOUND .
    WRITE:/ gv_err .
    LOOP AT gt_result .
    WRITE:/ .... .
    ENDLOOP .
    *--Serdar

  • How to execute unix shell script from Java ...

    Hi,
    Anyone know how to execute unix shell script from Java?
    Suppose I have several shell scripts written in perl or tcl or bash.
    I just want to catch the output of that script.
    Is there any ready to use module/object for this?
    Please let me know, this is quite urgent for my study assigment.
    Thanks in advance,
    Regards,
    me

    Look up Runtime.exec()

  • How to execute unix shell script in webdynpro?

    hi all,
      We have some iquirement of executing script in unix.If anyone know How to execute unix shell script in webdynpro?
    best regard
    reefish

    Ree,
    1. Find SSH client for windows, then execute SSH with Runtime.exec() on local host with arguments like remote host, auth, command to execute etc.
    2. Get SSH client in Java and execute SSH commands on remote host using pure Java API.
    Don't ask me for links, Google works today, I checked this
    Valery Silaev
    SaM Solutions
    http://www.sam-solutions.net

  • Through a java prog how to execute a unix script ?

    Hi !! I am a Java Developer . I have to work in Unix and Java in combination. Can you plz suggest me a solution for the below queries --
    1. Through a java prog how to execute a unix script.
    2. How to send the o/p of the script to a java prog so that it can be used in the java program to the prupose of display etc..

    Try this
    Process process = Runtime.getRuntime().exec("ps -ef");//write Your command here
                   InputStream in = process.getInputStream();
                   BufferedReader bufReader = new BufferedReader(new InputStreamReader(in));
                   String data=null;
                   while((data = bufReader.readLine())!=null)
                        System.out.println(data);   //do whatever you want to do with the output

  • How to execute PL/SQL from DOS PROMPT?

    Hello:
    I've seen that executing an SQl script via DOS prompt involves @script name, however all this seems to do is open the line editor. A GET command displays my script and sets the cursor on the next available line with the last line of the script with an asterics beside it. as does using the @scriptname command. I cannot do any commands like SAVE, RUN, etc.
    Any help is appreciated.

    Do you have a final / in your script to execute it (which is presumably an anon pl/sql block).

  • How to execute a sql file inside a plsql file?

    It's easy to exec a plsql inside a sql. Simply
    start my_proc.plsql
    exec my_proc;
    But how to execute a sql file inside a plsql file?
    declare ...
    begin
    start my_sql.sql?
    end;
    Thanks.
    - Zac

    Doesn't work. Even though @ is different from start in this case but it just doesn't like the way sql and plsql are mixed. For example:
    DECLARE n NUMBER := 0;
    BEGIN
    select COUNT(*) INTO n from user_tab_partitions;
    DBMS_OUTPUT.put_line('Number of partitioned tables = ' || to_char(n));
    if n = 0 then
    DBMS_OUTPUT.put_line('createViewsProcs.sql');
    @createViewsProcs.sql
    else
    DBMS_OUTPUT.put_line('createPartitionViewsProcs.sql');
    @createPartitionViewsProcs.sql
    end of;
    END;
    SQL> @postimp.sql
    SQL> DECLARE n NUMBER := 0;
    2 BEGIN
    3 select COUNT(*) INTO n from user_tab_partitions;
    4
    5 DBMS_OUTPUT.put_line('Number of partitioned tables = ' || to_char(n));
    6
    7 if n = 0 then
    8 DBMS_OUTPUT.put_line('createViewsProcs.sql');
    9 @createViewsProcs.sql
    9 SET SERVEROUTPUT ON SIZE UNLIMITED;
    10 SET TERM ON;
    11 SET ECHO ON;
    12 EXEC DBMS_OUTPUT.put_line('STARTING VIEWS, PROCS, ETC, THIS MAY TAKE A FEW MINUTES');
    13 EXEC DBMS_OUTPUT.put_line(SYSTIMESTAMP());
    14
    15
    16 CREATE OR REPLACE PACKAGE db_convert AS
    17 FUNCTION ......
    32 END;
    33 /
    SET SERVEROUTPUT ON SIZE UNLIMITED;
    ERROR at line 9:
    ORA-06550: line 9, column 5:
    PL/SQL: ORA-00922: missing or invalid option
    ...

  • Any ideas how to execute a .sql file on database server from java?

    Any ideas how to execute a xyz.sql file (which is fisically on
    database server) from java?
    thanks

    Try
    sqlplus "sys/oracletest as sysdba" @bpk.sql
    Working locally, and having set the ORACLE_SID, you don't need to specify the SqlNet alias (@testdb).
    Remember to put an exit at the end of the bpk.sql script.

  • Execute an SQL Script from Java (myScript.sql) ?

    Hello!
    I am a writing an SQL Script so that I can re-create my database on another server (im using my laptop to test it on first though).
    I'm connecting to mySQL server using JDBC which works fine, but I was wondering
    how can I run an entire script file, say myScript.sql from within a Java class??
    (an SQL Script is simply a file containing the regular SQL commands and expressions that you might enter at an sql command line prompt)
    example of an SQL Scritp: myScript.sql>>
    //#create new db
    CREATE DATABASE sample_db;
    //#set active db
    USE sample_db;
    //#set table paramaters
    CREATE TABLE monkeys
    (name CHAR(20),
      age INT UNSIGNED,
      sex ENUM('M','F')
    //#create standard monkeys
    INSERT INTO monkeys(name,age,sex) VALUES("Sammy",10,"M");
    INSERT INTO monkeys(name,age,sex) VALUES("Muncht",12,"M");
    INSERT INTO monkeys(name,age,sex) VALUES("Jill",8,"F");
    //#get recordset
    SELECT * FROM monkeys WHERE age < 50;Thanks for your help!

    The way I understand it is that your mysql.sql script file uses ';' as a delimeter between statements. So now what you can do is that read the whole file and put it inside a string/stringbuffer. Now put this string/stringbuffer to a stringTokenizer with delimeter set as ';'. this way you will recieve your exact statements without scratching your heads as where the statements begin/ends. :-)
    Now once you have your statements than its just a matter of executing them against the database.
    hope this helps.

  • How to Add an SQL script to another existing SQL script

    I have just created an SQL script and i need a way to join it with several other existing SQL scripts.
    I don't want to change any of the other scipts, i just need to add my new script on to the existing ones.
    I've looked at some of the functions and they don't seem to work for me.
    Let me use this as an example.
    Here is my new script:
    SELECT DISTINCT max(case when EC.EQUIPMENT_CLASS like '%_ERT' then 'Y' else 'N' end) over (partition by E.CURRENT_SERVICE_ID) as ERT
    FROM EQUIPMENT E,
    EQUIPMENT_TYPE ET,
    EQUIPMENT_CLASS EC
    WHERE E.EQUIPMENT_TYPE_ID = ET.EQUIPMENT_TYPE_ID
    and EC.EQUIPMENT_CLASS = ET.EQUIPMENT_CLASS
    and E.CURRENT_SERVICE_ID = 38514
    I need to add this to an existing script such as this:
    SELECT E.EQUIPMENT_NUMBER,
    E.EQUIPMENT_TYPE_ID,
    ET.EQUIPMENT_TYPE_DESC
    FROM EQUIPMENT E,
    EQUIPMENT_CATEGORY ECAT,
    EQUIPMENT_TYPE ET,
    EQUIPMENT_CLASS EC
    WHERE ET.EQUIPMENT_TYPE_ID = E.EQUIPMENT_TYPE_ID
    and EC.EQUIPMENT_CLASS = ET.EQUIPMENT_CLASS
    and EC.EQUIPMENT_CATEGORY = ECAT.EQUIPMENT_CATEGORY
    and E.EQUIPMENT_ID = 113950
    * The Reason why i can't just add the line i need together with the existing script, is because it's giving me invalid data from what i want to see. When i run them separately i get the desired results.
    Not sure if anything can be done like this or not, but if so, i'd appreciate a shove in the right direction.
    thanks

    I have just created an SQL script and i need a way to
    join it with several other existing SQL scripts.
    Do you simply want to append your newly created query to the file that contains an existing query ?
    >
    I've looked at some of the functions and they don't
    seem to work for me.
    Not sure how this is a SQL or PL/SQL related question, you'd probably want to just append the files using a text editor or maybe an OS command like cat or type.
    >
    * The Reason why i can't just add the line i need
    together with the existing script, is because it's
    giving me invalid data from what i want to see. When
    i run them separately i get the desired results.
    You may want to explain how the data is different from what you are expecting. In any case, your queries do not end with the sql terminator - the ";" character or a forward slash "/" at the first column of a line after the query; maybe that's the culprit.
    Consider this:
    SQL>
    SQL> host type c:\t1.sql
    select first_name from employees where rownum = 1
    SQL>
    SQL> @c:\t1.sql
      2  /
    FIRST_NAME
    Ellen
    SQL>
    SQL> host type c:\t2.sql
    select last_name from employees where rownum = 1
    SQL> @c:\t2.sql
      2  /
    LAST_NAME
    Abel
    SQL>
    SQL> host type t3.sql
    select first_name from employees where rownum = 1
    select last_name from employees where rownum = 1
    SQL> -- now, t3.sql contains both the queries of t1.sql and t2.sql
    SQL> -- however, they do not end with the sql terminators
    SQL>
    SQL> @c:\t3.sql
      2  /
    LAST_NAME
    Abel
    SQL> -- the first query was not executed...
    SQL>
    SQL> -- t3.sql has been fixed now
    SQL> host type t3.sql
    select first_name from employees where rownum = 1;
    select last_name from employees where rownum = 1;
    SQL> @c:\t3.sql
    FIRST_NAME
    Ellen
    LAST_NAME
    Abel
    SQL>pratz

Maybe you are looking for

  • Can I partition a 3tb fusion drive on a 2014 imac27", with boot camp, to let me install windows 7?

    I have used boot camp to create a partition for Windows 7 on 3 earlier Macs (iMac 24" 2007 / Mac Pro 2009 / Macbook Pro 2009) as well as a recent Macbook Air 2012. My main reason for this is to use Sage Account/Payroll, and also a couple of other Win

  • EMac Display issue

    This is a brand new eMac that has been working for 1 week, now the screen shakes and then goes back to normal, it is not one of the models in the eMac extended coverage program or what ever the name is I have already checked this. I am just wondering

  • Safari audio streaming to ATV2 since update

    After the latest update, can we now audio stream Safari (Pandora) via Airplay to the AppleTV (and audio-system)? I read references to people doing so, but can find no hard info. Thanks

  • How to use three part name with using dynamic query.

    Dear all, (sqlserver 2008 express r2) q1)following is showing error, is it possible to accomplish the task with out using dynamic query. DECLARE @A VARCHAR(100) DECLARE @A1 VARCHAR(100) SET @A='DB1' SET @A1='DBO' SELECT * FROM @[email protected] q2) table

  • Trouble inputting to an Array...

    I have the following setup: CLASS STORAGEBUSINESS private ArrayList<Customer> storageCustomer; // setters & getters public void setCustomers() {   if (storageCustomer == null)      storageCustomer = new ArrayList<Customer>(); public ArrayList getCust