简体   繁体   中英

trying to export the pl/sql script exctract to excel file which is currently extracting the data and putting it in text file

I have a PL/SQL script which generates a text file currently, but I need to generate excel file from the script. I have currently have pl/sql code like below,

BEGIN  
  --column headers  
  DBMS_OUTPUT.PUT_LINE(‘column name header 1 | column name header 2 | 
  column name header 3 |………..| column name header n’);  
END; /  
  --extract 
  (SELECT UNIQUE temptable.columnname1 || '|' ||  
  temptable.columnname2 || '|' ||                
  ‘columnname3’ || '|' ||               
  ………………                
  temptable.columnnamen '|' 
  FROM   temptable 
  WHERE  temptable.OUTPUT_INDICATOR = 'extract ready'); 

I have tried renaming the destination file name with .csv extension but all the data is getting copied to a single cell in an excel. Could anyone tell me how we modify the above code to extract data to excel file? Thanks.

使用像提取行这样的分隔符来构建标题行,但是所有分隔符都使用逗号。

In cvs you should use separator, that is recognized by your excel for your locale (eg for US it is comma (,) character, in other countries it could be semicolon(;))

Below is your example with comma separated values

BEGIN  
  --column headers  
  DBMS_OUTPUT.PUT_LINE(‘column name header 1 , column name header 2 , 
  column name header 3 ,……….., column name header n’);  
END; /  
  --extract 
  (SELECT UNIQUE temptable.columnname1 || ',' ||  
  temptable.columnname2 || ',' ||                
  ‘columnname3’ || ',' ||               
  ………………                
  temptable.columnnamen ',' 
  FROM   temptable 
  WHERE  temptable.OUTPUT_INDICATOR = 'extract ready'); 

Use comma , for column separator and \\r\\n for line separator:

BEGIN  
  --column headers  
  DBMS_OUTPUT.PUT_LINE(‘column name header 1 , column name header 2 , 
  column name header 3 ,……….., column name header n’ || '\r\n');  
END; /  
  --extract 
  (SELECT UNIQUE temptable.columnname1 || ',' ||  
  temptable.columnname2 || ',' ||                
  ‘columnname3’ || ',' ||               
  ………………                
  temptable.columnnamen || '\r\n' 
  FROM   temptable 
  WHERE  temptable.OUTPUT_INDICATOR = 'extract ready'); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM