Search code examples
export-to-excel

how to use batch script to export data from oracle into excel file with column names


  1. This is my bat script:

    set linesize 4000 pagesize 0 colsep ','
    set heading off feedback off verify off trimspool on trimout on
    
    spool &1
    
    select *
    from siebel.s_contact;
    
    spool off
    
    exit;
    
  2. Then I try to run below command. I can generate a Excel file with data but column names are missing.

    C:\Users\jy70606\Documents\Script>sqlplus -s geneos/password@database @C:\Users\jy
    70606\Documents\Script\daily.sql daily.csv
    
  3. My question is, how to make the columns available in my Excel?


Solution

  • Your Bat Script contains the following command to remove the columns

    set heading off

    You need to switch it on

    set heading on

    Reference: https://docs.oracle.com/cd/B19306_01/server.102/b14357/ch12040.htm#i2699001