Skip to Main Content
  • Questions
  • How to automatically execute sql queries in SQl developer

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Huy Toan.

Asked: August 18, 2016 - 3:56 am UTC

Last updated: August 19, 2016 - 4:29 am UTC

Version: 4.0

Viewed 10K+ times! This question is

You Asked

Hi thatjeffsmith,

I'm from Vietnam. I have a trouble need your help
I want to run this queries in SQL developer automatically, frequency will be daily:

spool D:\test.csv
select /*csv*/ * from dwh.DEPARTMENT_TCB where rownum <= 10
/
spool off
/

I tried to create a job but it did not work. This is my code to create my job:
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => '"DUONGCT"."toan2"',
job_type => 'PLSQL_BLOCK',
job_action => 'spool D:\test.csv
select /*csv*/ * from dwh.DEPARTMENT_TCB where rownum <= 10
/
spool off
/',
number_of_arguments => 0,
start_date => NULL,
repeat_interval => NULL,
end_date => NULL,
enabled => FALSE,
auto_drop => FALSE,
comments => '');

DBMS_SCHEDULER.SET_ATTRIBUTE(
name => '"DUONGCT"."toan2"',
attribute => 'logging_level', value => DBMS_SCHEDULER.LOGGING_OFF);
DBMS_SCHEDULER.enable(
name => '"DUONGCT"."toan2"');
END;


But the "Output Script" tab in SQL Developer prints: Anonymous block. I also tried to enable DBMS_OUTPUT but it failed. I think the reason why I can not create a job is that I don't have permission to do this (my bank' information security).

You can give me another method to automatically execute queries above or create a job?

Thank you in advance.
I'm looking forward to hearing from you soon!

and Connor said...

The "CSV" hint is specific to SQL Developer, so using a scheduler job is not going to work.

But SQL Developer has a command line interface. Take a look here

http://www.thatjeffsmith.com/archive/2013/07/sql-developer-4-0-and-the-command-line-interface-cli/

Alternatively, check out sqlcl,

http://www.oracle.com/technetwork/developer-tools/sqlcl/downloads/index.html

which allows similar facilities. Then you could schedule execution of those programs using the standard Windows scheduler (AT or Task Scheduler)

Is this answer out of date? If it is, please let us know via a Comment

More to Explore

DBMS_SCHEDULER

More on PL/SQL routine DBMS_SCHEDULER here