Search code examples
sqlwindowsoracle-databaseshellsqlcl

How can I most simply automate an Oracle query in windows?


I need to run the same damn Oracle query daily (and export the output, which I can do from the sql file itself). I'd like to automate using Windows Task Scheduler but it only opens the script, and it doesn't run it.

Is this feasible or is there an easier way?


Solution

  • Your description isn't very descriptive (we don't know how exactly you did that), but - here's a suggestion:

    • create a .bat script (let's call it a.bat) which will call your .sql (let's call it a.sql) script. Only one line in it:

      sqlplus scott/tiger@orcl @a.sql
      
    • a.sql is ... well, what it is, for example

      prompt Number of rows in EMP table
      
      select count(*) from emp;
      

    Create a job in Task Scheduler which will start a program (a.bat).

    I've just tried it (using that simple example I posted above) and got the result (saying that there are 14 rows in the table), so I hope you'll get it as well.