Solved

Avoid Blank Spaces for columns  While Spooling to Flat File

Posted on 2008-10-18
3
658 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
  • 2
3 Comments
 
LVL 142

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

758 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now