Export to Excel by each group [message #598760] |
Thu, 17 October 2013 09:02 |
|
epr55
Messages: 12 Registered: May 2011 Location: PR
|
Junior Member |
|
|
Hi
I have to export the results of a query to an Excel spreadsheet. Easy enough; however it is that I have to do it for each group. What I want to do is to be able to save it in a file that has the group number.
This is the query
Lets say that I have the groups in the valiable RegionID: 11213, 21345 and 6537
@export on;
@export set filename="C:\11213\IP_claims_11213_.xls"
select * from mytable
where RegionID=11213;
How I can make it that I do not have to manually change the folder name in the direction and the where statement for each RegionID?
|
|
|
|
|
Re: Export to Excel by each group [message #598766 is a reply to message #598760] |
Thu, 17 October 2013 09:40 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
epr55 wrote on Thu, 17 October 2013 19:32@export set filename="C:\11213\IP_claims_11213_.xls"
How I can make it that I do not have to manually change the folder name in the direction and the where statement for each RegionID?
You will have to either pass the RegionIds as parameters or assign it dynamically.
You can write an anonymous block, in a FOR loop, generate the SPOOL script.
FOR i IN (SELECT DISTINCT regionid FROM mytable) LOOP
<< prepare you SPOOL script here, the regionid folder would be i.regionid >>
<< like, select 'filename=C:\'||i.regionid||'\IP_claims_'||i.regionid||'_.xls' ....so on>>
END LOOP;
|
|
|
|
|
|
|
|
Re: Export to Excel by each group [message #598805 is a reply to message #598803] |
Thu, 17 October 2013 15:59 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
epr55 wrote on Fri, 18 October 2013 02:25I was informed that these commands are performed directly from ORACLE , which I do not have access. Is there another option?
Common man, you mentioned in the subject that you use Oracle DB, BTW you did not mention the version and the OS too.
Anyway, how can you access Oracle DB without using Oracle commands? What exactly are you doind?
|
|
|
|
|
|
Re: Export to Excel by each group [message #598827 is a reply to message #598826] |
Thu, 17 October 2013 17:27 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
epr55 wrote on Fri, 18 October 2013 03:52I felt sad I may have to go through each one to create the files, and the worst part is that is monthly!!
1. You mean the data is stored for all the months together in the same table?
2. Do you have RANGE PARTITION on monthly basis for the table to store the monthly data?
Regards,
Lalit
|
|
|
|
Re: Export to Excel by each group [message #598831 is a reply to message #598830] |
Thu, 17 October 2013 17:58 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
Look, it is not that placing the files in respective folder that consumes the time. It is the data retrieval that consumes the time.
1. Do you have the necessary indexes created?
2. Please post the number of records counts that you want to retrieve, and that the table has.
3. Is the table partitioned on monthly basis, I already pointed it in my previous post.
So finally, it is not a SQL question, rather, it's a performance tuning question, am I right?
|
|
|
|