Solved

Oracle SQL Developer (2.1.1.64) Script Automation

Posted on 2011-03-02
8
1,111 Views
Last Modified: 2012-05-11
Hi All,

I have a generic SQL (with three parameters), that I run at specific periods each day. When I have finished running each SQL, I export the results to CSV files which are automatically linked to an Access DB located on a server. The access DB holds all the data and serves as a tool for reporting and data analysis purposes.

My preferred outcome would be:

1. MS Command Script opens SQL developer
2. A macro (not sure what this would look like or if even possible) creates a connection instance, runs the SQL statement and exports each output file to my server
3. SQL developer is closed

Is anyone able to help me out here?

CF
SELECT a.dc_id || a.phys_whse_id       AS LocNo,
  a.prod_id                            AS Product,
  b.sdesc                              AS Description,
  a.po_id                              AS Purchase_Order,
  f.qty_ord/ c.vend_cse_rtl_unit       AS Orig_Ord_Qty_Cse,
  TO_CHAR(a.create_dtim, 'DD/MM/YYYY') AS Receipt_Date,
  a.cse_qty                            AS Cases_Rec,
  c.stor_ti                            AS Ti,
  c.stor_hi                            AS Hi,
  TO_CHAR(a.cde_dt, 'DD/MM/YYYY')      AS Code_Date,
  a.lot_no                             AS Lot_No,
  e.vend_id                            AS Vendor_ID,
  e.buyer                              AS Buyer,
  b.act_dept                           AS FineDept,
  b.cde_dt_var                         AS Min_Date,
  b.prod_max_dt                        AS Max_Date
FROM aothd a,
  iprod b,
  iprdd c,
  irctd d,
  ipo e,
  ipod f
WHERE a.prod_id  = b.prod_id
AND b.prod_id    = c.prod_id
AND a.lic_plt_id = d.lic_plt_id
AND a.po_id      = e.po_id
AND a.po_id      = f.po_id
AND a.prod_id    = f.prod_id
AND f.pod_id     =
  (SELECT MIN(x.pod_id)
  FROM ipod x
  WHERE f.dc_id = x.dc_id
  AND f.po_id   = x.po_id
  AND f.prod_id = x.prod_id
  )
AND a.phys_whse_id = 37
AND a.lhty_id     IN ('PU','MP')
AND TRUNC(a.create_dtim) BETWEEN to_date('31/01/2011', 'DD/MM/YYYY') AND to_date('06/02/2011', 'DD/MM/YYYY')
ORDER BY a.prod_id,
  a.create_dtim,
  a.po_id;

Open in new window

0
Comment
Question by:creativefusion
  • 4
  • 2
  • 2
8 Comments
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
Comment Utility
I know you probably like sql developer but have you considered maybe sqlplus?

You can create a sqlplus script and that can be easily sceduled.
0
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
Comment Utility
Here's a quick example of what I'm thinking.

The thing to note here is you are limited to a 32K size single line.  If a single line will exceed that it will require more work.
--set up some test tables and data
drop table t1 purge;
create table T1 (
	prod_id varchar2(10),
  	sdesc  varchar2(10),
  	po_id number
);

insert into t1 values('1234','desc A',1);
insert into t1 values('4321','desc B',2);
commit;

--sqlplus script starts here
--to run from a BAT/CMD file:  sqlplus -s /nolog @myscript.sql
set pages 0
set lines 32767
set trims on
set feedb off
set echo off
connect bud/bud
spool myFile.csv
SELECT EXTRACT(XMLAGG(XMLELEMENT("s",
           	prod_id || ',',
           	sdesc || ',',
           	po_id
         )), '/s/text()').getclobval()
           column1
FROM t1
group by prod_id
/
spool off

Open in new window

0
 

Author Comment

by:creativefusion
Comment Utility
Sorry I am limited to choices here. The business provides SQL Developer only and would not consider SQLPlus as an option.

Thanks for the suggestion.

CF
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
Comment Utility
I've never used sql developer so I cannot confirm if what you want to do is possible.  I've looked around and cannot find anything even hinting that it is possible.

You might contact Oracle Support to see if this can be done without some key of keyboard scripting program.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
SQL Developer is not intended for that purpose, and there is no way to implement it besides heavy hacking like using AutoIt or the like, as slightwv correctly stated.

SQL*Plus is part of the Oracle client, and hence should be available anyway.
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
Comment Utility
>>SQL*Plus is part of the Oracle client,

I believe the issue is: SQL Developer doesn't require a client install.  It's about the only Oracle product that doesn't.


I strongly suggest you recommend to your IT staff they allow you at least the Oracle Instant Client w/ SQL Plus.  It doesn't take up much room nor does it create a log of registry/garbage in the system.
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
Haven't been aware of that you do not need a client for Developer (using it seldom myself).

For using SQL*Plus, and not having any kind of client installed, you can trick into using the server installation files to execute commands (by having a Oracle share defined, and extending PATH to include the binaries - requires that the server is the same platform as the client). But having an Instant Client is a much better option.
0
 

Author Comment

by:creativefusion
Comment Utility
Okay guys. Great help thanks. I''l look into this and post back the outcome. Cheers, CF
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now