Skip to Main Content
  • Questions
  • Generate .csv file using Oracle Pl Sql

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Sambhav.

Asked: December 03, 2015 - 3:36 pm UTC

Last updated: January 25, 2016 - 5:31 pm UTC

Version: Oracle 11g

Viewed 10K+ times! This question is

You Asked

Hi ,

We have a requirement where we need to generate .csv file (extract from some table) in Window server.

I don't have access to Create Directory. Could you please on this.Is there any way in which we can generate .csv file in our local machine.

Thanks In Advance

Regards
Samby

and Chris said...

If you want to create the csv locally, then you could use SQL Developer's CSV export functionality. Or you could write a script to spool it from SQL Dev, SQL*Plus or SQLcl.

SQL Dev and SQLcl both support the /*csv*/ comment to automatically format the result of a query as csv:

with rws as (
  select rownum r, dbms_random.string('a', 10) s from dual connect by level <= 10
)
select /*csv*/* from rws;

"R","S"
1,"LXbfQqpnAP"
2,"mZRCpBKRIl"
3,"YGafpGmjuA"
4,"hIIBZSKkjG"
5,"RCdnOrIEQk"
6,"pNJaPBeNOL"
7,"rXwJRMrcnY"
8,"HbUmZmxikF"
9,"rbwEaxJnPn"
10,"eCHfPiPVQB"

 10 rows selected 

Rating

  (2 ratings)

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

Comments

Using Dynamic SQL

Rajeshwaran Jeyabal, December 04, 2015 - 11:24 am UTC

Alexander, January 25, 2016 - 4:41 pm UTC

Hi guys,

I am trying to dump a large amount xml clob data to a file. I was thinking about trying to use SQLcl for this for some of it's more modern formatting features. But it appears that this is a client side only tool? Is it possible to use this on the database server like SQLPlus?

Thanks.
Chris Saxon
January 25, 2016 - 5:31 pm UTC

Yes, you can install SQLcl on your server and use it in a similar way to SQL*Plus.

More to Explore

DBMS_RANDOM

More on PL/SQL routine DBMS_RANDOM here