Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Dynamically write data into csv file chr(10) through UTL_FILE.

Ashu OrclOct 27 2016 — edited Nov 15 2016

Hi All,

Below is the version of my database;

Oracle Database 11g EE High Perf Release 11.2.0.4.0 - 64bit Production

I am trying to achieve below logic;

In my application I have multiple reports which needs to be written in csv/tab delimited files. For which, instead of writing those files to application and then transferring it to end user, I am preferring that let files written on database server through UTL_FILE. I am able to write the same, but as there are many reports so I have multiple queries for each of them, thus I want to avoid writing procedures/packages for each of them separately. So I am thinking of a solution where there will be a common procedure/package for writing files to database through UTL_FILE which will accept couple of input parameters like below;

1) Header query parameter -> which will have query for column headers and will return one row.

2) Main query parameter -> which will have query for main/actual data and will return thousands of rows.

3) File name parameter -> which give path to system where file needs to be stored.

My challenge is I am unable to pass a query as parameters which will be fired and whatever result given will be written through utl_file. Basically first two parameters will be dynamic there will be NO constant number of columns defined.

Hope I have made myself clear.

Thanks in advance

Regards,

Ash

This post has been answered by Saubhik Banerjee on Oct 27 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 5 2016
Added on Oct 27 2016
4 comments
849 views