Question

I try many times to export my result into .csv file but I'm always fail. I read lot of articles related in my problem.

Look at my query:

spool sample.csv

SELECT /*html*/(CODE_SALESROOM) POS_ID, (NAME_SALESROOM) POS_NAME
FROM OWNER_DWH.DC_SALESROOM
WHERE CODE_SALESROOM NOT IN ('XAP', 'XNA', '10001');

spool off;

The output of this, when I export in a csv file is only the query not the real result.

What's wrong in my command to export the result?

Please help me. Thanks

Was it helpful?

Solution

Make sure that your query returns values. You can set various parameters of Sql plus before spooling to get desired out put. Below is the list that I use before spooling. And since your are generating csv, it should be comma separated

set echo off
set termout off
set define off
set heading off
set pagesize 10000
set linesize 500
set feedback off
set verify off
set trimspool on

spool sample.csv

SELECT 'POS_ID,POS_NAME' from dual; -- header list

SELECT CODE_SALESROOM || ',' || NAME_SALESROOM
FROM OWNER_DWH.DC_SALESROOM
WHERE CODE_SALESROOM NOT IN ('XAP', 'XNA', '10001');

spool off;

You can modify the set parameters based on your requirement.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top