How to export data to .csv and send that file to folder using sql commands?

Really hoping someone can provide some code sample or point me in the right direction (with examples using sql).
I am using oracle 11g with plsql developer. My requirement is that the data retrieval should be automatic. That means when query a data in oracle table , the data should be convert into .csv file and then it should send that to some specific folder.
Example: Assume that student_sub1 table have all students subject1 data.when i write a query like select * from student_sub1 where student=1, the student1 data should convert into .csv file and then the .csv file should go to student1 folder.
Hence I am requesting you to suggest me how write a sql code to convert the data into .csv file and to create a folder to send that file using oracle.
Your inputs helps me alot.
Thanks in advance!!!!
Waiting for your replies.... Cheers

981145 wrote:
Really hoping someone can provide some code sample or point me in the right direction (with examples using sql).
I am using oracle 11g with plsql developer. My requirement is that the data retrieval should be automatic. That means when query a data in oracle table , the data should be convert into .csv file and then it should send that to some specific folder.
Example: Assume that student_sub1 table have all students subject1 data.when i write a query like select * from student_sub1 where student=1, the student1 data should convert into .csv file and then the .csv file should go to student1 folder.
Hence I am requesting you to suggest me how write a sql code to convert the data into .csv file and to create a folder to send that file using oracle.
Your inputs helps me alot.
Thanks in advance!!!!
Waiting for your replies.... CheersSET COLSEP ,
spool student1.csv
select * from student_sub1 where student=1;
spool off
How do I ask a question on the forums?
SQL and PL/SQL FAQ
Handle:     981145
Status Level:     Newbie
Registered:     Jan 10, 2013
Total Posts:     25
Total Questions:     10 (8 unresolved)
I extend my condolences to you since you rarely get answers to your questions here.

Similar Messages

  • Export data in CSV and store the file in local drive

    Hi,
    Here is the requirements.
    Fetch the values from table (around 60000 records), and export them into CSV file and store the file in local drive.
    I have written servlet to to this and it is working fine expect saving the file in local drive. At the moment, it is asking to save as in local drive. i want to save the file automatically in particular path (/var/www/files/). Below is the code.
    String file = "CandidatesDetails" + sd + ".csv";
                        queryString = "select * from candidate where candidate.status='A'";
                        connection = ConnectionPoolHelper.getConnection();
                        response.setContentType("application/csv");
                        response.setHeader("content-disposition", "filename=" + file);
                        System.out.println("Query= " + queryString);
                        ps = connection.prepareStatement(queryString,
                                  ResultSet.TYPE_SCROLL_INSENSITIVE,
                                  ResultSet.CONCUR_READ_ONLY);
                        rs = ps.executeQuery();
                        datas = "CANDIDATE ID,CANDIDATE TITLE,FIRST NAME,LAST NAME,E-MAIL,NATIONALITY ID,NATIONALITY,COUNTRY ID,COUNTRY NAME,INDUSTRY ID,INDUSTRY DESCRIPTION,EXPERIENCE,DATE OF BIRTH,HEAR ABOUT US\n";
                        oout.write(datas);
                        String country = "";
                        String nationality = "";
                        String hearABtUs = "";
                        while (rs.next()) {
                             nationality = rs.getString(7);
                             if (nationality == null)
                                  nationality = "";
                             else if (nationality.equals("null"))
                                  nationality = "";
                             country = rs.getString(9);
                             if (country == null)
                                  country = "";
                             else if (country.equals("null"))
                                  country = "";
                             hearABtUs = rs.getString(14);
                             if (hearABtUs == null)
                                  hearABtUs = "";
                             else if (hearABtUs.equals("null"))
                                  hearABtUs = "";
                             else
                                  hearABtUs = hearABtUs.replaceAll(",", ";");
                             datas = rs.getInt(1) + "," + rs.getString(2) + ","
                                       + rs.getString(3) + "," + rs.getString(4) + ","
                                       + rs.getString(5) + "," + rs.getInt(6) + ","
                                       + nationality + "," + rs.getInt(8) + "," + country
                                       + "," + rs.getInt(10) + "," + rs.getString(11)
                                       + "," + rs.getString(12) + "," + rs.getString(13)
                                       + "," + hearABtUs + "\n";
                             oout.write(datas); Regards,
    Dongan.

    Here is the first few lines
    public void doGet(HttpServletRequest request, HttpServletResponse response)
                   throws ServletException, IOException {
              HttpSession session = request.getSession(true);
              String datas = "";
              PreparedStatement ps = null;
              ResultSet rs = null;
              String queryString = "";
              Connection connection;
              PrintWriter oout = response.getWriter();
              java.util.Date d = new java.util.Date();
              SimpleDateFormat dateformat = new SimpleDateFormat("dd-MMM-yyyy");
              String sd = dateformat.format(d);
              tryAt the moment, when i run http://localhost:8080/project/CandidatesDetail, it will ask me to save the file somewhere. I should manually mention the path to save the file. what i want is, it should automatically save it in the location C:\projects\files\.
    thanks.
    Regards,
    Dongan
    Edited by: Dongan on Oct 26, 2007 5:22 AM

  • How to load data to dimensions and fact table is it simialr to sql server

    How to load data to dimensions and fact table in a data ware house environment, is it simialr to sql server, oracle?
    Never migrated or loaded data to datawarehouse server.
    I have an interview and am really confused if they ask anything related to the dataware house side elements.
    Coudl you please if you don't mind provide me some steps and dimension and fact table info, an example only.
    Atleast for my knowledge.
    Thank you very much for the helpful info.

    Some discussions in previous forums should help you
    http://forums.sdn.sap.com/thread.jspa?threadID=2019448
    http://forums.sdn.sap.com/thread.jspa?threadID=1908902
    In the SAP tutorial, you can see a sample example of making fact tables.
    http://help.sap.com/businessobject/product_guides/boexir32SP1/en/xi321_ds_tutorial_en.pdf
    Arun

  • How to export data to .csv file  ?

    Hi guys, I know this topic is covered many times in this forum. How do I export my table data to a csv file when my data already has some , (commas) in it. For example, I have two columns in a table, ID and DESCRIPTION. The DESCRIPTION column has data which has , (commas) in it. When I export the data using the following script, I see multiple columns in my excel file as DESCRIPTION has data with commas and each part of it is shown as a separate column in excel sheet.
    set heading off
    set echo off;
    set pause off;
    spool tbl_account.csv;
    select To_Char(ID)|| ',' || To_Char(Description) From tbl_account;
    spool off;
    Thanks in advance

    Have you thought about putting those values between quotation marks?
    "test,test" for example would end up in one cell.
    C.

  • How to export data in csv

    hai ;
    can u advise me, how to export the value from databse table to csc and pdf format
    please can you provide some sample code
    thanks..

    Doesn't work that way here. Try something, post some code if you get stuck.
    No-one is going to write your code for you.
    You will need to use JDBC to query your database, and there are plenty of CSV libraries available for free, or write your own.

  • How to write to both .csv and binary format files

    Hi, I am very new to labview. I have been given the programme to process measurement data and save the data into .csv format. But the file in .csv format is very large. So on top of the .csv, I would like to save the processed data into another binary file at the same time. I have attached the .vi to this post, I tried to add an write to binary function to the programme, but there are quite a few errors. Could someone give me a hand please? Thanks a lot.
    Attachments:
    RF Analyze_test.vi ‏40 KB

    I agree that TDMS is worthwhile looking into.
    As far as your issue: which errors are you referring to? Are you referring to the missing assignments to the tunnels? That's due to the fact that you did not wire a value for the other case. An output tunnel must generate a value for all cases. You can right-click on the output tunnel and select "Use default if unwired". In this case the value will be the default value for whatever datatype is being generated. If you are referring to other errors, please be specific.

  • How to export report to excel and to text file in previewer

    How to export report to excel?
    And, it takes long time for generate report to rtf or pdf file in previewer.
    How to speed up the process? or, it's better generate report to text file directly by Run_product?
    Please help!

    You can generate report to tab delimite format that can be imported to excel.
    As for the performance question, because reports can't specify what format when you run against previewer, so I don't know what previewer you are talking about. Generate to file is always faster than to your application previewer (assume) because you have one more step after output generated in the file: read from file and render it. Depends on the render and size of the output, it may have significant performance difference.
    Thanks,
    -Shaun

  • How to Export data to memory and Import data from memory?

    hi
    I have the follwoing some code of program.
    The data is not filled from memory. I have to find what is the wrong in code.
    REPORT ZIFT_TEST1..
    SELECT-OPTIONS : so_budat FOR bkpf-budat,
                     sd_saknr FOR ska1-saknr.
      EXPORT so_budat TO MEMORY ID 'ZBUDAT'.
      EXPORT sd_saknr TO MEMORY ID 'ZSAKNR'.
      SUBMIT ZIFT_TEST2 AND RETURN.
    REPORT ZIFT_TEST2..
    SELECT-OPTIONS so_budat FOR bsis-budat NO DATABASE SELECTION.
    SELECT-OPTIONS: SD_SAKNR    FOR  SKA1-SAKNR MATCHCODE OBJECT SAKO.
      import so_budat = so_budat from memory id 'ZBUDAT'.
      import sd_saknr from memory id 'ZSAKNR'.
    Regards
    Iftikhar Ali
    Islamabad.

    Program1----
    REPORT demo_program_rep3 NO STANDARD PAGE HEADING.
    DATA: number TYPE i,
    itab TYPE TABLE OF i.
    SET PF-STATUS 'MYBACK'.
    DO 5 TIMES.
    number = sy-index.
    APPEND number TO itab.
    WRITE / number.
    ENDDO.
    TOP-OF-PAGE.
    WRITE 'Report 2'.
    ULINE.
    AT USER-COMMAND.
    CASE sy-ucomm.
    WHEN 'MBCK'.
    EXPORT itab TO MEMORY ID 'HK'.
    LEAVE.
    ENDCASE.
    Program2----
    REPORT demo_programm_leave NO STANDARD PAGE HEADING.
    DATA: itab TYPE TABLE OF i,
    num TYPE i.
    SUBMIT demo_program_rep3 AND RETURN.
    IMPORT itab FROM MEMORY ID 'HK'.
    LOOP AT itab INTO num.
    WRITE / num.
    ENDLOOP.
    TOP-OF-PAGE.
    WRITE 'Report 1'.
    ULINE.
    end of program 2----
    Now you copy this programs with same name as i mentioned and execute demo_programm_leave Program.you will understnad clearly.
    Notes::: A logical memory model illustrates how the main memory is distributed from the view of executable programs. A distinction is made here between external sessions and internal sessions .
    An external session is usually linked to an R/3 window. You can create an external session by choosing System/Create session, or by entering /o in the command field. An external session is broken down further into internal sessions. Program data is only visible within an internal session. Each external session can include up to 20 internal sessions (stacks).
    Every program you start runs in an internal session.
    To copy a set of ABAP variables and their current values (data cluster) to the ABAP memory, use the EXPORT TO MEMORY ID statement. The (up to 32 characters) is used to identify the different data clusters.
    If you repeat an EXPORT TO MEMORY ID statement to an existing data cluster, the new data overwrites the old.
    To copy data from ABAP memory to the corresponding fields of an ABAP program, use the IMPORT FROM MEMORY ID statement.

  • How to export data to csv file on a scheduled basis

    Hi,
    I'm trying to do something that should probably be simple but I just can't figure it out.
    I have an existing MS SQL database (2008 R2). I have a very simple SQL script. I need to run this script on a daily basis and save the results as a .csv file.
    I've tried creating a job in SQL Manager - that didn't work. Then I found a tutorial that had me use MS Visual Studio... couldn't get that to function either.
    Can someone help me understand what program I should be using, and how to go about creating this as a task / job that can run on a scheduled basis?
    Thank you!
    Chris

    Hi, you can follow the below steps to get your work done -
    Create a batch file (.bat) and dump the following text into it
              sqlcmd -S myServer -d myDB -E -Q "select col1, col2, col3 from SomeTable" -o "MyData.csv" -h-1 -s"," -w 700
              Replace myServer with your server name,
    myDB with your Database name and then replace the query with your actual query.
             -h-1 removes column name headers from the result
             -s"," sets the column seperator to ,
             -w 700 sets the row width to 700 chars (this will need to be as wide as the longest row or it will wrap to the next line)
    Save the batch file and the schedule it as per your requirement.
    Hope, that helps.
    -Vinay Pugalia
    If a post answers your question, please click "Mark As Answer" on that post and
    "Mark as Helpful".
    Web : Inkey Solutions
    Blog : My Blog
    Email : Vinay Pugalia

  • How can I create an csv/excel file using pl/sql and then sending that file

    How can I create an csv/excel file using pl/sql and then sending that file to a clients site using pl/sql?
    I know how to create the csv/excel file but I can't figure out how I would get it to the clients site.

    968776 wrote:
    How can I create an csv/excel file using pl/sql and then sending that file to a clients site using pl/sql?
    I know how to create the csv/excel file but I can't figure out how I would get it to the clients site.You are trying to do it at a wrong place..
    Whay do you want database (pl/sql) code to do these things?
    Anyhow, you may be interested in :
    {message:id=9360007}
    {message:id=9984244}

  • How to import data from CSV file with columns separated by semicolon?

    I migrate database from MS SQL 2008 to ORACLE 11g
    I export data to CSV file from MS SQL
    then I try to import it to Oracle
    several tables goes fine using Import data option in the SQL Developer
    Standard CSV files with data separated by comma were imported.
    chars, date (with format string), and integer data are imported via import wizard without problems
    the problems were when I try to import table with noninteger numbers with modal part separated by comma not by dot
    comma is the standard separator for columns in CSV file
    so I must change the standard separator to semicolon
    then the import wizard have problem to correct recognize the columns data because it use only standard CSV comma separator :-/
    In SQL Developer 1.5.3 Tools -> Preferences -> Migration -> Data Move Options
    I change "End of Column Delimiter" to ; but it doens't work
    Is this possible to change the standard column separator for import data wizzard in SQL Developer 1.5.3?
    Or maybe someone know how to import data in SQL Developer 1.5.3 from CSV when CSV colunn separator is set to semicolon?

    A new preference has been added to customize the import delimiter in main code line. This should be available as part of future release.

  • How to export report IN CSV format through JAVA.

    how to export report in csv format.when try to export in csv format.its exporting into csv but report not containing column heading , report heading and it showing all the data in a single line.we have integrated the reports with java.

    Use a Java API which can create PDF files based on some collection of plain vanilla Java objects (List, String, Number, etc).
    Google can find them all. Just feed it with something like "Java PDF API" or so. A commonly used one is iText.
    That said, when talking about this in JSP context, ensure that you do NOT write raw Java code in JSP files using scriptlets. Raw Java code belongs in Java classes. In such case you need a Servlet. In JSP just use taglibs and EL to interact with backend Java code and data. Scriptlets are discouraged since over a decade.

  • How to export data with column headers in sql server 2008 with bcp command?

    Hi all,
    I want know "how to export data with column headers in sql server 2008 with bcp command", I know how to import data with import and export wizard. when i
    am trying to import data with bcp command data has been copied but column names are not came.
    I am using the below query:-
    EXEC master..xp_cmdshell
    'BCP "SELECT  * FROM   [tempdb].[dbo].[VBAS_ErrorLog] " QUERYOUT "D:\Temp\SQLServer.log" -c -t , -T -S SERVER-A'
    Thanks,
    SAAD.

    Hi All,
    I have done as per your suggestion but here i have face the below problem, in print statment it give correct query, in EXEC ( EXEC master..xp_cmdshell @BCPCMD) it was displayed error message like below
    DECLARE @BCPCMD
    nvarchar(4000)
    DECLARE @BCPCMD1
    nvarchar(4000)
    DECLARE @BCPCMD2
    nvarchar(4000)
    DECLARE @SQLEXPRESS
    varchar(50)
    DECLARE @filepath
    nvarchar(150),@SQLServer
    varchar(50)
    SET @filepath
    = N'"D:\Temp\LDH_SQLErrorlog_'+CAST(YEAR(GETDATE())
    as varchar(4))
    +RIGHT('00'+CAST(MONTH(GETDATE())
    as varchar(2)),2)
    +RIGHT('00'+CAST(DAY(GETDATE())
    as varchar(2)),2)+'.log" '
    Set @SQLServer
    =(SELECT
    @@SERVERNAME)
    SELECT @BCPCMD1
    = '''BCP "SELECT 
    * FROM   [tempdb].[dbo].[wErrorLog] " QUERYOUT '
    SELECT @BCPCMD2
    = '-c -t , -T -S '
    + @SQLServer + 
    SET @BCPCMD
    = @BCPCMD1+ @filepath 
    + @BCPCMD2
    Print @BCPCMD
    -- Print out below
    'BCP "SELECT 
    * FROM   [tempdb].[dbo].[wErrorLog] " QUERYOUT "D:\Temp\LDH_SQLErrorlog_20130313.log" -c -t , -T -S servername'
    EXEC
    master..xp_cmdshell
    @BCPCMD
      ''BCP' is not recognized as an internal or external command,
    operable program or batch file.
    NULL
    if i copy the print ourt put like below and excecute the CMD it was working fine, could you please suggest me what is the problem in above query.
    EXEC
    master..xp_cmdshell
    'BCP "SELECT  * FROM  
    [tempdb].[dbo].[wErrorLog] " QUERYOUT "D:\Temp\LDH_SQLErrorlog_20130313.log" -c -t , -T -S servername '
    Thanks, SAAD.

  • How to export data from a Oracle table to a delimited file?

    I know how to load delimited file into a table, but how to export
    data from a Oracle table to a delimited file?
    Thanks in advance.

    Try looking at this link, it's long but there's three different solutions discussed in it. If you look at Barbara Boehmer's
    solution in her posts in the link below you'll see that she's addressed your concerns with spool files.
    Re: utl_smtp and triggers

  • How to export data from a spread sheet which has multiple work sheets?

    How to export data from a spread sheet which has multiple work sheets to a single text file with fixed length fields?

    Hello s1,
    saving them as CSV will not give a fixed legth output but, as the naming says, a Character Separated Value file.
    Regards
    Marcus

Maybe you are looking for