Unload data to flat file, fixed length [message #270126] |
Tue, 25 September 2007 17:08  |
kham2k
Messages: 34 Registered: May 2007
|
Member |
|
|
Greetings all!!
I want to ask you is if i want to unload a table to a flat we use spool. but with spool, i know how to delimit it with , or | but how can i generate a file which will be fixed length?
Thanks Allot
|
|
|
|
|
|
|
Re: Unload data to flat file, fixed length [message #270397 is a reply to message #270389] |
Wed, 26 September 2007 14:52   |
diku
Messages: 23 Registered: April 2007
|
Junior Member |
|
|
Declare two cursors , one for your master and another for your detail recordset. Loop through your detail cursor everytime you find a new master record from your master cursor.Obviously you'd need to have some sort of a relation between these two which I presume you'd have.
Now that the records are being pulled it's just a question of fomatting them properly. Play around with RPAD and LPAD and it should not be too difficult
|
|
|
Re: Unload data to flat file, fixed length [message #270403 is a reply to message #270389] |
Wed, 26 September 2007 15:17  |
 |
Michel Cadot
Messages: 68761 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
Here's a beginning of a way:
SQL> col filler fold_before
SQL> select decode(nvl(rn,1),1,d.deptno) deptno,
2 decode(nvl(rn,1),1,d.dname) dname,
3 ' ' filler,
4 e.empno, e.ename
5 from dept d,
6 (select empno, ename, deptno,
7 row_number () over (partition by deptno order by empno) rn
8 from emp) e
9 where e.deptno (+) = d.deptno
10 order by d.deptno, e.empno
11 /
DEPTNO DNAME
---------- --------------
FILLER EMPNO ENAME
------ ---------- ----------
10 ACCOUNTING
7782 CLARK
7839 KING
7934 MILLER
20 RESEARCH
7369 SMITH
7566 JONES
7788 SCOTT
7876 ADAMS
7902 FORD
30 SALES
7499 ALLEN
7521 WARD
7654 MARTIN
7698 BLAKE
7844 TURNER
7900 JAMES
40 OPERATIONS
15 rows selected.
Regards
Michel
|
|
|