Home » SQL & PL/SQL » SQL & PL/SQL » how to escape comma while exporting data from table into csv file. (10g)
how to escape comma while exporting data from table into csv file. [message #550455] |
Mon, 09 April 2012 11:48  |
 |
kiran111
Messages: 49 Registered: October 2011
|
Member |
|
|
hi friends,
how we can escape comma while exporting data from table into csv file.
CREATE TABLE emp
(
EMPNO NUMBER(4) NOT NULL,
ENAME VARCHAR2(10 BYTE),
JOB VARCHAR2(9 BYTE),
MGR NUMBER(4),
HIREDATE DATE,
address varchar2(100),
SAL NUMBER(7,2),
COMM NUMBER(7,2),
DEPTNO NUMBER(2)
);
Insert into emp
(EMPNO, ENAME, JOB, MGR, ADDRESS, HIREDATE, SAL, DEPTNO)
Values
(7369, 'SMITH', 'CLERK', 7902, 'PEI,CANADA', TO_DATE('12/17/1980 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 800, 20);
Insert into emp
(EMPNO, ENAME, JOB, MGR, ADDRESS, HIREDATE, SAL, DEPTNO)
Values
(7499, 'ALLEN', 'SALESMAN', 7698, 'Bangalore,INDIA', TO_DATE('02/20/1981 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 1600, 30);
Insert into emp
(EMPNO, ENAME, JOB, MGR, ADDRESS, HIREDATE, SAL, DEPTNO)
Values
(7521, 'WARD', 'SALESMAN', 7698, '80,hyderabad,india', TO_DATE('02/22/1981 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 1250, 30);
Insert into emp
(EMPNO, ENAME, JOB, MGR, ADDRESS, HIREDATE, SAL, DEPTNO)
Values
(7566, 'JONES', 'MANAGER', 7839, '#20,PEI,canada', TO_DATE('04/02/1981 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2975, 20);
Insert into emp
(EMPNO, ENAME, JOB, MGR, ADDRESS, HIREDATE, SAL, DEPTNO)
Values
(7782, 'CLARK', 'MANAGER', 7839, '#10-20,US', TO_DATE('06/09/1981 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2450, 10);
i have to export data from emp table which has address column and address column contain comma,
when i am running below script, the comma part in address field comes in next tab in csv file, is there any way we can avoid shifting to next tab and can have complete address in one tab.
set echo off
set verify off
set termout on
set heading off
set pages 50000
set feedback off
set newpage none
set linesize 160
spool e:/file_csv.csv
SELECT 'EMPNO,ENAME,JOB,ADDRESS,MGR,HIREDATE,DEPTNO' from dual
union all
SELECT empno||','||ename||','||job||','||address||','||mgr||','||hiredate||','||DEPTNO
FROM emp
WHERE deptno in (10,20);
spool off;
exit;
|
|
|
|
|
|
|
|
|
|
Re: how to escape comma while exporting data from table into csv file. [message #550527 is a reply to message #550498] |
Tue, 10 April 2012 02:07   |
flyboy
Messages: 1903 Registered: November 2006
|
Senior Member |
|
|
kiran111 wrote on Tue, 10 April 2012 04:16i tried, but now all data are coming in only first tab instead of seperate tab in csv file.
Did you not forget to tell your favourite spreadsheet application, that the separator character is now pipe '|' and not comma ','?
As Excel takes it directly from Windows Control Panel -> Regional and Language Options settings (at least its online help says so - you really should get acquainted with it; by the way, I found semicolon ';' in that setting), it is probably not wise to change it as it may affect behaviour of other programs/activities. Especially when enclosing strings between double quotes (") (as Michel advised) produces correct result.
|
|
|
|
Goto Forum:
Current Time: Sat Aug 23 23:58:06 CDT 2025
|