| SQL CSV Spool with UNION ALL [message #417129] |
Thu, 06 August 2009 04:30  |
dior
Messages: 25 Registered: April 2009
|
Junior Member |
|
|
Hi,
I m spooling some things to a csv file and that works very well, but now i need to spool a file where i have joined 3 tables with union all.
any idea how i can do this?
so far I use a sql file like this:
@echo off
xxx/yyy@DB.com
set pagesize 0
set heading off
set linesize 1024
set echo off
set feed off
set tab off
set trimout on
set trims on
spool values.csv
SELECT 'Value1;value2' from dual;
SELECT
PL1.VALUE || ';' ||
PL2.VALUE || ';'
FROM STAT_123 ST
PL_VC PL1 ,
PL_VC PL2
WHERE ST.CLASS = PL1.ID (+)
AND ST.LEVEL = PL2.ID (+);
spool off
quit
The SQL Statement I need to put into such a SQL is:
select STT.VALUE, ST.FACN from ESTAT ST, ESTATTYP STT
where ST.FTYPE = STT.VID
union all
select NG1T.VALUE, NG1.FACN from TRAGWGTYP NG1T, TRAGWG NG1
where NG1.STYPE = NG1T.VID
union all
select PT.VALUE, P.FACN from mas, MASTYP PT
where P.PTYPE = PT.VID
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Re: SQL CSV Spool with UNION ALL [message #417354 is a reply to message #417162] |
Fri, 07 August 2009 10:14   |
kumar29
Messages: 6 Registered: July 2009
|
Junior Member |
|
|
Lets try this way. Don't prepare your whole result as a single string with separator ";"
Use ',' instead of ";"
set pagesize 0
set heading off
set linesize 1024
set echo off
set feed off
set tab off
set trimout on
set trims on
set colsep ","
spool c:\xxxx01.csv;
select STT.VALUE, ST.FACN from ESTAT ST, ESTATTYP STT
where ST.FTYPE = STT.VID
union all
select NG1T.VALUE, NG1.FACN from TRAGWGTYP NG1T, TRAGWG NG1
where NG1.STYPE = NG1T.VID
union all
select PT.VALUE, P.FACN from mas, MASTYP PT
where P.PTYPE = PT.VID
/
spool off
/
|
|
|
|
| Re: SQL CSV Spool with UNION ALL [message #417358 is a reply to message #417354] |
Fri, 07 August 2009 10:20  |
 |
Michel Cadot
Messages: 68770 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
As far a I can see this does not add anything to the previous answers and it is NOT formated.
Please read OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code (See SQL Formatter), use code tags.
Use the "Preview Message" button to verify.
Regards
Michel
|
|
|
|