Solved

Avoid Blank Spaces for columns  While Spooling to Flat File

Posted on 2008-10-18
3
665 Views
Last Modified: 2013-12-19
Hello,
I have to use spool to export data to flat file(.txt) in oracle.  These columns available in my table (TBL_JE_OUTPUT )
RECORD_TYPE,BUSINESSUNIT, JOURNALID,LEDGER,JOURNAL_LINE_NO, ACCOUNT- These are few columns in my table all are varchar2 type.
The columns like JournalID,Ledger,Jounrnal_line_no,Account are nullable. when I'm using a select query to spool data to text file - the columns having null value, the text file contains blank spaces for the columns which are null. Please find the example below.
SQL> set colsep ''
SQL> select RECORD_TYPE,BUSINESSUNIT, JOURNALID,LEDGER,JOURNAL_LINE_NO, ACCOUNT from tbl_je_output;

RBUSINJOURNALID LEDGER    JOURNAACCOUN
--------------------------------------
LADV01                    000005155110
LADV01                    000006155110
LADV01                    000007155110
LADV01                    000008155110
LADV01                    000009155110
LADV01                    000010155110
LADV01                    000011337016
HAFC01NEXT      ACTUALS
LAFC01                    000001152312
LAFC01                    000002
HAFC01NEXT      ACTUALS

But I want the output as under:
LADV01000005155110
LADV01000006155110
LADV01000007155110
LADV01000008155110
LADV01000009155110
LADV01000010155110
LADV01000011337016
HAFC01NEXTACTUALS
LAFC01000001152312
LAFC01000002
HAFC01NEXTACTUALS

How to achieve this? Please helpme out as this is an urgent requirement
0
Comment
Question by:msasikala
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22747377
what about this:
 select RECORD_TYPE || BUSINESSUNIT ||  JOURNALID || LEDGER || JOURNAL_LINE_NO || ACCOUNT from tbl_je_output;

Open in new window

0
 
LVL 7

Expert Comment

by:DiscoNova
ID: 22747890
If simple concatenation of the fields is all that is required, angelIII's solution is the correct way to go. On the other hand, if the concatenated fields might consist of (leadin or trailing) whitespaces, you might need to do something like this:
select
  trim(RECORD_TYPE)
  ||
  trim(BUSINESSUNIT)
  ||
  trim(JOURNALID)
  ||
  trim(LEDGER)
  ||
  trim(JOURNAL_LINE_NO)
  ||
  trim(ACCOUNT)
from
  tbl_je_output;

Open in new window

0
 
LVL 7

Accepted Solution

by:
DiscoNova earned 125 total points
ID: 22747898
Oh yes... and if the fields might contain whitespace in some other part than their beginning or ending, you would need to use the translate-function (or something similar) to get rid of them.
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
Via a live example, show how to take different types of Oracle backups using RMAN.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question